···11+-- user_subscriptions: tracks Stripe subscription state per identity
22+create table "public"."user_subscriptions" (
33+ "identity_id" uuid not null,
44+ "stripe_customer_id" text not null,
55+ "stripe_subscription_id" text,
66+ "plan" text,
77+ "status" text,
88+ "current_period_end" timestamp with time zone,
99+ "created_at" timestamp with time zone not null default now(),
1010+ "updated_at" timestamp with time zone not null default now()
1111+);
1212+1313+alter table "public"."user_subscriptions" enable row level security;
1414+1515+CREATE UNIQUE INDEX user_subscriptions_pkey ON public.user_subscriptions USING btree (identity_id);
1616+1717+alter table "public"."user_subscriptions" add constraint "user_subscriptions_pkey" PRIMARY KEY using index "user_subscriptions_pkey";
1818+1919+CREATE UNIQUE INDEX user_subscriptions_stripe_customer_id_key ON public.user_subscriptions USING btree (stripe_customer_id);
2020+2121+CREATE UNIQUE INDEX user_subscriptions_stripe_subscription_id_key ON public.user_subscriptions USING btree (stripe_subscription_id);
2222+2323+alter table "public"."user_subscriptions" add constraint "user_subscriptions_identity_id_fkey" FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE;
2424+2525+grant delete on table "public"."user_subscriptions" to "anon";
2626+grant insert on table "public"."user_subscriptions" to "anon";
2727+grant references on table "public"."user_subscriptions" to "anon";
2828+grant select on table "public"."user_subscriptions" to "anon";
2929+grant trigger on table "public"."user_subscriptions" to "anon";
3030+grant truncate on table "public"."user_subscriptions" to "anon";
3131+grant update on table "public"."user_subscriptions" to "anon";
3232+3333+grant delete on table "public"."user_subscriptions" to "authenticated";
3434+grant insert on table "public"."user_subscriptions" to "authenticated";
3535+grant references on table "public"."user_subscriptions" to "authenticated";
3636+grant select on table "public"."user_subscriptions" to "authenticated";
3737+grant trigger on table "public"."user_subscriptions" to "authenticated";
3838+grant truncate on table "public"."user_subscriptions" to "authenticated";
3939+grant update on table "public"."user_subscriptions" to "authenticated";
4040+4141+grant delete on table "public"."user_subscriptions" to "service_role";
4242+grant insert on table "public"."user_subscriptions" to "service_role";
4343+grant references on table "public"."user_subscriptions" to "service_role";
4444+grant select on table "public"."user_subscriptions" to "service_role";
4545+grant trigger on table "public"."user_subscriptions" to "service_role";
4646+grant truncate on table "public"."user_subscriptions" to "service_role";
4747+grant update on table "public"."user_subscriptions" to "service_role";
4848+4949+-- user_entitlements: feature access decoupled from billing
5050+create table "public"."user_entitlements" (
5151+ "identity_id" uuid not null,
5252+ "entitlement_key" text not null,
5353+ "granted_at" timestamp with time zone not null default now(),
5454+ "expires_at" timestamp with time zone,
5555+ "source" text,
5656+ "metadata" jsonb
5757+);
5858+5959+alter table "public"."user_entitlements" enable row level security;
6060+6161+CREATE UNIQUE INDEX user_entitlements_pkey ON public.user_entitlements USING btree (identity_id, entitlement_key);
6262+6363+alter table "public"."user_entitlements" add constraint "user_entitlements_pkey" PRIMARY KEY using index "user_entitlements_pkey";
6464+6565+CREATE INDEX user_entitlements_identity_id_idx ON public.user_entitlements USING btree (identity_id);
6666+6767+CREATE INDEX user_entitlements_expires_at_idx ON public.user_entitlements USING btree (expires_at);
6868+6969+alter table "public"."user_entitlements" add constraint "user_entitlements_identity_id_fkey" FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE;
7070+7171+grant delete on table "public"."user_entitlements" to "anon";
7272+grant insert on table "public"."user_entitlements" to "anon";
7373+grant references on table "public"."user_entitlements" to "anon";
7474+grant select on table "public"."user_entitlements" to "anon";
7575+grant trigger on table "public"."user_entitlements" to "anon";
7676+grant truncate on table "public"."user_entitlements" to "anon";
7777+grant update on table "public"."user_entitlements" to "anon";
7878+7979+grant delete on table "public"."user_entitlements" to "authenticated";
8080+grant insert on table "public"."user_entitlements" to "authenticated";
8181+grant references on table "public"."user_entitlements" to "authenticated";
8282+grant select on table "public"."user_entitlements" to "authenticated";
8383+grant trigger on table "public"."user_entitlements" to "authenticated";
8484+grant truncate on table "public"."user_entitlements" to "authenticated";
8585+grant update on table "public"."user_entitlements" to "authenticated";
8686+8787+grant delete on table "public"."user_entitlements" to "service_role";
8888+grant insert on table "public"."user_entitlements" to "service_role";
8989+grant references on table "public"."user_entitlements" to "service_role";
9090+grant select on table "public"."user_entitlements" to "service_role";
9191+grant trigger on table "public"."user_entitlements" to "service_role";
9292+grant truncate on table "public"."user_entitlements" to "service_role";
9393+grant update on table "public"."user_entitlements" to "service_role";