a tool for shared writing and social publishing
1-- user_subscriptions: tracks Stripe subscription state per identity
2create table "public"."user_subscriptions" (
3 "identity_id" uuid not null,
4 "stripe_customer_id" text not null,
5 "stripe_subscription_id" text,
6 "plan" text,
7 "status" text,
8 "current_period_end" timestamp with time zone,
9 "created_at" timestamp with time zone not null default now(),
10 "updated_at" timestamp with time zone not null default now()
11);
12
13alter table "public"."user_subscriptions" enable row level security;
14
15CREATE UNIQUE INDEX user_subscriptions_pkey ON public.user_subscriptions USING btree (identity_id);
16
17alter table "public"."user_subscriptions" add constraint "user_subscriptions_pkey" PRIMARY KEY using index "user_subscriptions_pkey";
18
19CREATE UNIQUE INDEX user_subscriptions_stripe_customer_id_key ON public.user_subscriptions USING btree (stripe_customer_id);
20
21CREATE UNIQUE INDEX user_subscriptions_stripe_subscription_id_key ON public.user_subscriptions USING btree (stripe_subscription_id);
22
23alter table "public"."user_subscriptions" add constraint "user_subscriptions_identity_id_fkey" FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE;
24
25grant delete on table "public"."user_subscriptions" to "anon";
26grant insert on table "public"."user_subscriptions" to "anon";
27grant references on table "public"."user_subscriptions" to "anon";
28grant select on table "public"."user_subscriptions" to "anon";
29grant trigger on table "public"."user_subscriptions" to "anon";
30grant truncate on table "public"."user_subscriptions" to "anon";
31grant update on table "public"."user_subscriptions" to "anon";
32
33grant delete on table "public"."user_subscriptions" to "authenticated";
34grant insert on table "public"."user_subscriptions" to "authenticated";
35grant references on table "public"."user_subscriptions" to "authenticated";
36grant select on table "public"."user_subscriptions" to "authenticated";
37grant trigger on table "public"."user_subscriptions" to "authenticated";
38grant truncate on table "public"."user_subscriptions" to "authenticated";
39grant update on table "public"."user_subscriptions" to "authenticated";
40
41grant delete on table "public"."user_subscriptions" to "service_role";
42grant insert on table "public"."user_subscriptions" to "service_role";
43grant references on table "public"."user_subscriptions" to "service_role";
44grant select on table "public"."user_subscriptions" to "service_role";
45grant trigger on table "public"."user_subscriptions" to "service_role";
46grant truncate on table "public"."user_subscriptions" to "service_role";
47grant update on table "public"."user_subscriptions" to "service_role";
48
49-- user_entitlements: feature access decoupled from billing
50create table "public"."user_entitlements" (
51 "identity_id" uuid not null,
52 "entitlement_key" text not null,
53 "granted_at" timestamp with time zone not null default now(),
54 "expires_at" timestamp with time zone,
55 "source" text,
56 "metadata" jsonb
57);
58
59alter table "public"."user_entitlements" enable row level security;
60
61CREATE UNIQUE INDEX user_entitlements_pkey ON public.user_entitlements USING btree (identity_id, entitlement_key);
62
63alter table "public"."user_entitlements" add constraint "user_entitlements_pkey" PRIMARY KEY using index "user_entitlements_pkey";
64
65CREATE INDEX user_entitlements_identity_id_idx ON public.user_entitlements USING btree (identity_id);
66
67CREATE INDEX user_entitlements_expires_at_idx ON public.user_entitlements USING btree (expires_at);
68
69alter table "public"."user_entitlements" add constraint "user_entitlements_identity_id_fkey" FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE;
70
71grant delete on table "public"."user_entitlements" to "anon";
72grant insert on table "public"."user_entitlements" to "anon";
73grant references on table "public"."user_entitlements" to "anon";
74grant select on table "public"."user_entitlements" to "anon";
75grant trigger on table "public"."user_entitlements" to "anon";
76grant truncate on table "public"."user_entitlements" to "anon";
77grant update on table "public"."user_entitlements" to "anon";
78
79grant delete on table "public"."user_entitlements" to "authenticated";
80grant insert on table "public"."user_entitlements" to "authenticated";
81grant references on table "public"."user_entitlements" to "authenticated";
82grant select on table "public"."user_entitlements" to "authenticated";
83grant trigger on table "public"."user_entitlements" to "authenticated";
84grant truncate on table "public"."user_entitlements" to "authenticated";
85grant update on table "public"."user_entitlements" to "authenticated";
86
87grant delete on table "public"."user_entitlements" to "service_role";
88grant insert on table "public"."user_entitlements" to "service_role";
89grant references on table "public"."user_entitlements" to "service_role";
90grant select on table "public"."user_entitlements" to "service_role";
91grant trigger on table "public"."user_entitlements" to "service_role";
92grant truncate on table "public"."user_entitlements" to "service_role";
93grant update on table "public"."user_entitlements" to "service_role";