MDL-38173 Courselib: Make the distinct clause in the upgrade step more cross DB.