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