UPDATE question_sets qs
SET owner_type = 'SUB_COURSE',
    owner_id = sm.legacy_sub_course_id
FROM sub_modules sm
WHERE qs.owner_type = 'SUB_MODULE'
  AND qs.owner_id = sm.id
  AND qs.set_type = 'PRACTICE'
  AND sm.legacy_sub_course_id IS NOT NULL;

DROP TABLE IF EXISTS sub_module_practices CASCADE;
DROP TABLE IF EXISTS sub_module_videos CASCADE;
DROP TABLE IF EXISTS sub_modules CASCADE;
DROP TABLE IF EXISTS modules CASCADE;
DROP TABLE IF EXISTS levels CASCADE;

ALTER TABLE courses DROP COLUMN IF EXISTS sub_category_id;
DROP TABLE IF EXISTS course_sub_categories CASCADE;

-- Best-effort rollback to old expectation.
UPDATE user_practice_progress
SET sub_course_id = 1
WHERE sub_course_id IS NULL;
ALTER TABLE user_practice_progress
ALTER COLUMN sub_course_id SET NOT NULL;

