RezinaLMS-BackEnd/db/migrations/000111_subscription_plan_is_free.up.sql
Yared Yemane 1eb03b7e03 Add free subscription plans and enforce unique billing periods.
Introduce is_free plans with gateway-free checkout enrollment, require positive pricing for paid plans, and block duplicate category plus period combinations including free versus paid.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 21:32:33 +03:00

16 lines
461 B
SQL

ALTER TABLE subscription_plans
ADD COLUMN IF NOT EXISTS is_free BOOLEAN NOT NULL DEFAULT FALSE;
-- Legacy zero-price rows become explicitly free before the price constraint is enforced.
UPDATE subscription_plans
SET is_free = TRUE
WHERE price = 0
AND is_free = FALSE;
ALTER TABLE subscription_plans
ADD CONSTRAINT chk_subscription_plans_free_price
CHECK (
(is_free = TRUE AND price = 0)
OR (is_free = FALSE AND price > 0)
);