Skip to main content

max / makenotwork

1.1 KB · 23 lines History Blame Raw
1 -- App-level sync subscriptions (GO, BB, AF cloud sync).
2 -- One subscription per user per app. Payment goes to MNW's own Stripe account.
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 -- Tier: 'standard' for GO/BB (single tier), 'light'/'standard'/'large' for AF blob tiers
10 tier TEXT NOT NULL DEFAULT 'standard',
11 status TEXT NOT NULL DEFAULT 'active',
12 -- AF blob storage: tracked in bytes, NULL for non-blob apps
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 -- One active subscription per user per app
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