Files
digital-psychology/apps/api/migrations/000017_membership_plans.up.sql
T
jackyu66gitandCursor 882c01d81a feat(ECR-014): MembershipPlan 套餐配置并 Closed
membership_plans 表、admin 套餐页、Grant/CreateOrder 读表;
Loop continuous 自动 Approve/Closed。Next:ECR-015 RedemptionCode。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 18:03:38 +08:00

28 lines
819 B
SQL

-- ECR-014 MembershipPlan
CREATE TABLE IF NOT EXISTS membership_plans (
code varchar(32) PRIMARY KEY,
title varchar(64) NOT NULL,
duration_days int NOT NULL CHECK (duration_days > 0),
amount_cents int NOT NULL CHECK (amount_cents >= 0),
active boolean NOT NULL DEFAULT true,
updated_at timestamptz NOT NULL DEFAULT now()
);
INSERT INTO membership_plans(code, title, duration_days, amount_cents, active)
VALUES
('month', '月卡', 31, 2500, true),
('quarter', '季卡', 92, 6800, true),
('year', '年卡', 366, 19800, true)
ON CONFLICT (code) DO NOTHING;
INSERT INTO admin_role_permissions(role_id, code)
SELECT r.id, p.code
FROM admin_roles r
CROSS JOIN (VALUES
('admin.membership.plans.read'),
('admin.membership.plans.write')
) AS p(code)
WHERE r.name = 'super_admin'
ON CONFLICT DO NOTHING;