gcx/backend/migrations/007_create_coupon_rules.sql

20 lines
902 B
SQL

-- 007: Coupon rules - 7 configurable rules per coupon (issuer-service)
CREATE TABLE IF NOT EXISTS coupon_rules (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
coupon_id UUID NOT NULL REFERENCES coupons(id) ON DELETE CASCADE,
rule_type VARCHAR(30) NOT NULL CHECK (rule_type IN (
'transferable', -- 1. 是否可转让
'resale_limit', -- 2. 转售次数限制
'user_restriction', -- 3. 用户限制(年龄/职业等)
'per_user_limit', -- 4. 每用户限购
'store_restriction', -- 5. 指定商户
'stacking', -- 6. 叠加使用
'min_purchase' -- 7. 最低消费
)),
rule_value JSONB NOT NULL DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_coupon_rules_coupon_id ON coupon_rules(coupon_id);
CREATE INDEX idx_coupon_rules_type ON coupon_rules(rule_type);