BEGIN; DROP TRIGGER delete_chapter_quizzes ON exam_prep.units; DROP FUNCTION exam_prep.delete_chapter_quizzes(); DROP TRIGGER protect_learning_question_set_type ON question_sets; DROP FUNCTION exam_prep.protect_quiz_question_set_type(); DROP TRIGGER chapter_quiz_parent ON exam_prep.practice_parents; DROP TRIGGER chapter_quiz_shell_parent ON exam_prep.lesson_practices; DROP FUNCTION exam_prep.check_chapter_quiz_parent(); -- Restore pre-migration lessons; newly authored lessons remain in their container. UPDATE exam_prep.unit_module_lessons l SET unit_module_id = b.unit_module_id, sort_order = b.sort_order, publish_status = b.publish_status, access_tier = b.access_tier FROM exam_prep.chapter_lesson_migration_backup b WHERE b.id = l.id; DROP TABLE exam_prep.chapter_lesson_migration_backup; DROP TABLE exam_prep.chapter_lesson_containers; UPDATE exam_prep.catalog_courses c SET category = b.category FROM exam_prep.course_category_migration_backup b WHERE c.id = b.id; DROP TABLE exam_prep.course_category_migration_backup; COMMIT;