RezinaLMS-BackEnd/db/migrations/000008_course_purchases.down.sql

22 lines
1.6 KiB
PL/PgSQL

BEGIN;
DROP TABLE course_purchases;
ALTER TABLE payments DROP CONSTRAINT payments_course_or_plan;
ALTER TABLE payments DROP COLUMN course_id;
-- Materialize inherited tiers before restoring the legacy premium cascade.
UPDATE exam_prep.units u SET access_tier=c.access_tier FROM exam_prep.catalog_courses c WHERE u.catalog_course_id=c.id AND u.access_tier='INHERIT';
UPDATE exam_prep.unit_modules m SET access_tier=u.access_tier FROM exam_prep.units u WHERE m.unit_id=u.id AND m.access_tier='INHERIT';
UPDATE exam_prep.unit_module_lessons l SET access_tier=m.access_tier FROM exam_prep.unit_modules m WHERE l.unit_module_id=m.id AND l.access_tier='INHERIT';
ALTER TABLE exam_prep.units DROP CONSTRAINT chk_exam_prep_units_access_tier;
ALTER TABLE exam_prep.units ADD CONSTRAINT chk_exam_prep_units_access_tier CHECK (access_tier IN ('FREE','PREMIUM'));
ALTER TABLE exam_prep.units ALTER COLUMN access_tier SET DEFAULT 'PREMIUM';
ALTER TABLE exam_prep.unit_modules DROP CONSTRAINT chk_exam_prep_unit_modules_access_tier;
ALTER TABLE exam_prep.unit_modules ADD CONSTRAINT chk_exam_prep_unit_modules_access_tier CHECK (access_tier IN ('FREE','PREMIUM'));
ALTER TABLE exam_prep.unit_modules ALTER COLUMN access_tier SET DEFAULT 'PREMIUM';
ALTER TABLE exam_prep.unit_module_lessons DROP CONSTRAINT chk_exam_prep_unit_module_lessons_access_tier;
ALTER TABLE exam_prep.unit_module_lessons ADD CONSTRAINT chk_exam_prep_unit_module_lessons_access_tier CHECK (access_tier IN ('FREE','PREMIUM'));
ALTER TABLE exam_prep.unit_module_lessons ALTER COLUMN access_tier SET DEFAULT 'PREMIUM';
ALTER TABLE exam_prep.catalog_courses DROP COLUMN price, DROP COLUMN currency;
COMMIT;