CREATE TABLE "deal_drafts" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_id" uuid NOT NULL,
	"payload" jsonb NOT NULL,
	"title" text,
	"is_starred" boolean DEFAULT false NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "deal_images" ADD COLUMN "draft_id" uuid;--> statement-breakpoint
ALTER TABLE "deal_drafts" ADD CONSTRAINT "deal_drafts_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "deal_drafts_vendor_updated_idx" ON "deal_drafts" USING btree ("vendor_id","updated_at" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "deal_drafts_purge_idx" ON "deal_drafts" USING btree ("updated_at") WHERE "deal_drafts"."is_starred" = false;--> statement-breakpoint
ALTER TABLE "deal_images" ADD CONSTRAINT "deal_images_draft_id_deal_drafts_id_fk" FOREIGN KEY ("draft_id") REFERENCES "public"."deal_drafts"("id") ON DELETE cascade ON UPDATE no action;