表级 CHECK
current_period_end > current_period_start
access_until >= current_period_start
(channel = 'crypto') = (provider_ref IS NULL)
channel <> 'crypto' OR auto_renew = 0
(status = 'revoked') = (revoked_at IS NOT NULL)
索引 / 唯一约束
plan_subscriptions_live_access_until (access_until) WHERE status IN ('active','past_due','grace')
UNIQUE plan_subscriptions_one_crypto (user_id, channel, provider_mode) WHERE channel = 'crypto' AND status NOT IN ('expired','revoked') AND ended_at IS NULL
UNIQUE plan_subscriptions_provider_ref (channel, provider_ref, provider_mode) WHERE provider_ref IS NOT NULL
plan_subscriptions_user_status (user_id, status)