1+ CREATE TYPE "public "." subscription_status" AS ENUM(' incomplete' , ' incomplete_expired' , ' trialing' , ' active' , ' past_due' , ' canceled' , ' unpaid' , ' paused' );-- > statement-breakpoint
2+ ALTER TYPE " public" ." grant_type" ADD VALUE ' subscription' BEFORE ' purchase' ;-- > statement-breakpoint
3+ CREATE TABLE "limit_override " (
4+ " user_id" text PRIMARY KEY NOT NULL ,
5+ " credits_per_block" integer NOT NULL ,
6+ " block_duration_hours" integer NOT NULL ,
7+ " weekly_credit_limit" integer NOT NULL ,
8+ " created_at" timestamp with time zone DEFAULT now() NOT NULL ,
9+ " updated_at" timestamp with time zone DEFAULT now() NOT NULL
10+ );
11+ -- > statement-breakpoint
12+ CREATE TABLE "subscription " (
13+ " stripe_subscription_id" text PRIMARY KEY NOT NULL ,
14+ " stripe_customer_id" text NOT NULL ,
15+ " user_id" text ,
16+ " stripe_price_id" text NOT NULL ,
17+ " status" " subscription_status" DEFAULT ' active' NOT NULL ,
18+ " billing_period_start" timestamp with time zone NOT NULL ,
19+ " billing_period_end" timestamp with time zone NOT NULL ,
20+ " cancel_at_period_end" boolean DEFAULT false NOT NULL ,
21+ " canceled_at" timestamp with time zone ,
22+ " created_at" timestamp with time zone DEFAULT now() NOT NULL ,
23+ " updated_at" timestamp with time zone DEFAULT now() NOT NULL
24+ );
25+ -- > statement-breakpoint
26+ ALTER TABLE " credit_ledger" ADD COLUMN " stripe_subscription_id" text ;-- > statement-breakpoint
27+ ALTER TABLE " limit_override" ADD CONSTRAINT " limit_override_user_id_user_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
28+ ALTER TABLE " subscription" ADD CONSTRAINT " subscription_user_id_user_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
29+ CREATE INDEX "idx_subscription_customer " ON " subscription" USING btree (" stripe_customer_id" );-- > statement-breakpoint
30+ CREATE INDEX "idx_subscription_user " ON " subscription" USING btree (" user_id" );-- > statement-breakpoint
31+ CREATE INDEX "idx_subscription_status " ON " subscription" USING btree (" status" ) WHERE " subscription" ." status" = ' active' ;-- > statement-breakpoint
32+ CREATE INDEX "idx_credit_ledger_subscription " ON " credit_ledger" USING btree (" stripe_subscription_id" ," type" ," created_at" );
0 commit comments