MDL-57649 mod_lesson: Improvement to upgrade query.