75 lines
3.0 KiB
SQL
75 lines
3.0 KiB
SQL
CREATE TABLE "stripe_checkout_session" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"stripe_session_id" text NOT NULL,
|
|
"stripe_customer_id" text,
|
|
"mode" text NOT NULL,
|
|
"status" text,
|
|
"payment_status" text,
|
|
"amount_total" integer,
|
|
"currency" text,
|
|
"success_url" text,
|
|
"cancel_url" text,
|
|
"stripe_payment_intent_id" text,
|
|
"stripe_subscription_id" text,
|
|
"metadata" text,
|
|
"expires_at" timestamp,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "stripe_checkout_session_stripe_session_id_unique" UNIQUE("stripe_session_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stripe_customer" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"stripe_customer_id" text NOT NULL,
|
|
"email" text,
|
|
"name" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "stripe_customer_stripe_customer_id_unique" UNIQUE("stripe_customer_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stripe_invoice" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"stripe_invoice_id" text NOT NULL,
|
|
"stripe_customer_id" text,
|
|
"stripe_subscription_id" text,
|
|
"status" text,
|
|
"amount_due" integer,
|
|
"amount_paid" integer,
|
|
"currency" text,
|
|
"invoice_url" text,
|
|
"invoice_pdf" text,
|
|
"period_start" timestamp,
|
|
"period_end" timestamp,
|
|
"paid_at" timestamp,
|
|
"metadata" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "stripe_invoice_stripe_invoice_id_unique" UNIQUE("stripe_invoice_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stripe_subscription" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"stripe_subscription_id" text NOT NULL,
|
|
"stripe_customer_id" text NOT NULL,
|
|
"stripe_price_id" text,
|
|
"status" text NOT NULL,
|
|
"current_period_start" timestamp,
|
|
"current_period_end" timestamp,
|
|
"cancel_at_period_end" text,
|
|
"canceled_at" timestamp,
|
|
"ended_at" timestamp,
|
|
"metadata" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "stripe_subscription_stripe_subscription_id_unique" UNIQUE("stripe_subscription_id")
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "stripe_checkout_session" ADD CONSTRAINT "stripe_checkout_session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stripe_customer" ADD CONSTRAINT "stripe_customer_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stripe_invoice" ADD CONSTRAINT "stripe_invoice_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stripe_subscription" ADD CONSTRAINT "stripe_subscription_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; |