RezinaLMS-BackEnd/db/migrations/000093_exam_prep_practice_parents.up.sql
Yared Yemane 208c653e02 feat: attach exam prep practices to catalog courses and units
Introduce exam_prep.practice_parents, migrate lesson links, and add create/list APIs with progress rollups, sequential gating, and RBAC permissions.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 04:18:25 -07:00

27 lines
1.1 KiB
SQL

-- Exam-prep practices can attach to catalog courses, units, or lessons (one parent per practice).
CREATE TABLE exam_prep.practice_parents (
id BIGSERIAL PRIMARY KEY,
practice_id BIGINT NOT NULL REFERENCES exam_prep.lesson_practices (id) ON DELETE CASCADE,
parent_kind VARCHAR(30) NOT NULL CHECK (parent_kind IN ('CATALOG_COURSE', 'UNIT', 'LESSON')),
parent_id BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (practice_id, parent_kind, parent_id),
UNIQUE (parent_kind, parent_id)
);
INSERT INTO exam_prep.practice_parents (practice_id, parent_kind, parent_id)
SELECT
id,
'LESSON',
unit_module_lesson_id
FROM exam_prep.lesson_practices;
DROP INDEX IF EXISTS idx_exam_prep_lesson_practices_lesson_id;
DROP INDEX IF EXISTS idx_exam_prep_lesson_practices_lesson_created;
ALTER TABLE exam_prep.lesson_practices
DROP COLUMN unit_module_lesson_id;
CREATE INDEX idx_exam_prep_practice_parents_practice_id ON exam_prep.practice_parents (practice_id);
CREATE INDEX idx_exam_prep_practice_parents_lookup ON exam_prep.practice_parents (parent_kind, parent_id);