| 1 |
|
| 2 |
|
| 3 |
CREATE TABLE app_sync_subscriptions ( |
| 4 |
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 5 |
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 6 |
app_id UUID NOT NULL REFERENCES sync_apps(id) ON DELETE CASCADE, |
| 7 |
stripe_subscription_id TEXT NOT NULL UNIQUE, |
| 8 |
stripe_customer_id TEXT NOT NULL, |
| 9 |
|
| 10 |
tier TEXT NOT NULL DEFAULT 'standard', |
| 11 |
status TEXT NOT NULL DEFAULT 'active', |
| 12 |
|
| 13 |
storage_limit_bytes BIGINT, |
| 14 |
current_period_start TIMESTAMPTZ, |
| 15 |
current_period_end TIMESTAMPTZ, |
| 16 |
canceled_at TIMESTAMPTZ, |
| 17 |
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() |
| 18 |
); |
| 19 |
|
| 20 |
|
| 21 |
CREATE UNIQUE INDEX idx_app_sync_subs_user_app ON app_sync_subscriptions(user_id, app_id); |
| 22 |
CREATE INDEX idx_app_sync_subs_stripe ON app_sync_subscriptions(stripe_subscription_id); |
| 23 |
|