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>
16 lines
461 B
SQL
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)
|
|
);
|