CREATE TYPE "public"."checkout_status" AS ENUM('pending', 'completed', 'expired');--> statement-breakpoint CREATE TYPE "public"."subscription_status" AS ENUM('active', 'canceled', 'revoked', 'past_due');--> statement-breakpoint CREATE TABLE "checkouts" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "account_id" uuid NOT NULL, "project_id" uuid NOT NULL, "polar_checkout_id" text NOT NULL, "wm_name" text NOT NULL, "package_id" uuid NOT NULL, "vcpu" real NOT NULL, "ram" integer NOT NULL, "disk" integer NOT NULL, "status" "checkout_status" DEFAULT 'pending' NOT NULL, "wm_id" uuid, "created_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "checkouts_polar_checkout_id_unique" UNIQUE("polar_checkout_id") ); --> statement-breakpoint CREATE TABLE "subscriptions" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "account_id" uuid NOT NULL, "wm_id" uuid, "polar_subscription_id" text NOT NULL, "status" "subscription_status" DEFAULT 'active' NOT NULL, "current_period_start" timestamp with time zone, "current_period_end" timestamp with time zone, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "subscriptions_polar_subscription_id_unique" UNIQUE("polar_subscription_id") ); --> statement-breakpoint ALTER TABLE "accounts" ADD COLUMN "polar_customer_id" text;--> statement-breakpoint ALTER TABLE "wms" ADD COLUMN "polar_subscription_id" text;--> statement-breakpoint ALTER TABLE "checkouts" ADD CONSTRAINT "checkouts_account_id_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."accounts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkouts" ADD CONSTRAINT "checkouts_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkouts" ADD CONSTRAINT "checkouts_package_id_packages_id_fk" FOREIGN KEY ("package_id") REFERENCES "public"."packages"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkouts" ADD CONSTRAINT "checkouts_wm_id_wms_id_fk" FOREIGN KEY ("wm_id") REFERENCES "public"."wms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_account_id_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."accounts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_wm_id_wms_id_fk" FOREIGN KEY ("wm_id") REFERENCES "public"."wms"("id") ON DELETE no action ON UPDATE no action;