-- Restores legacy lesson columns. Rows will have NULL question_set_id until repopulated.

ALTER TABLE sub_module_lessons
    ADD COLUMN IF NOT EXISTS question_set_id BIGINT REFERENCES question_sets(id) ON DELETE CASCADE,
    ADD COLUMN IF NOT EXISTS intro_video_url TEXT;

UPDATE sub_module_lessons
SET intro_video_url = teaching_video_url
WHERE teaching_video_url IS NOT NULL;

ALTER TABLE sub_module_lessons
    DROP COLUMN IF EXISTS title,
    DROP COLUMN IF EXISTS description,
    DROP COLUMN IF EXISTS thumbnail,
    DROP COLUMN IF EXISTS teaching_text,
    DROP COLUMN IF EXISTS teaching_image_url,
    DROP COLUMN IF EXISTS teaching_audio_url,
    DROP COLUMN IF EXISTS teaching_video_url;
