ALTER TYPE "public"."admin_action" ADD VALUE 'REQUEST_REFUND';--> statement-breakpoint
ALTER TYPE "public"."admin_action" ADD VALUE 'RESEND_RECEIPT';--> statement-breakpoint
ALTER TYPE "public"."admin_target_type" ADD VALUE 'PURCHASE';--> statement-breakpoint
ALTER TYPE "public"."payment_status" ADD VALUE 'REFUND_REQUESTED';--> statement-breakpoint
CREATE TABLE "cart_items" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"user_id" uuid NOT NULL,
	"deal_id" uuid NOT NULL,
	"qty" integer NOT NULL,
	"added_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "cart_items_user_deal_unique" UNIQUE("user_id","deal_id")
);
--> statement-breakpoint
CREATE TABLE "system_health_findings" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"kind" text NOT NULL,
	"entity_type" text NOT NULL,
	"entity_id" text NOT NULL,
	"detail" text,
	"first_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
	"last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
	"resolved_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "deal_images" ALTER COLUMN "approval_status" SET DATA TYPE text;--> statement-breakpoint
ALTER TABLE "deal_images" ALTER COLUMN "approval_status" SET DEFAULT 'PENDING'::text;--> statement-breakpoint
ALTER TABLE "image_uploads" ALTER COLUMN "approval_status" SET DATA TYPE text;--> statement-breakpoint
ALTER TABLE "image_uploads" ALTER COLUMN "approval_status" SET DEFAULT 'PENDING'::text;--> statement-breakpoint
DROP TYPE "public"."image_approval_status";--> statement-breakpoint
CREATE TYPE "public"."image_approval_status" AS ENUM('PENDING', 'APPROVED', 'REJECTED');--> statement-breakpoint
ALTER TABLE "deal_images" ALTER COLUMN "approval_status" SET DEFAULT 'PENDING'::"public"."image_approval_status";--> statement-breakpoint
ALTER TABLE "deal_images" ALTER COLUMN "approval_status" SET DATA TYPE "public"."image_approval_status" USING "approval_status"::"public"."image_approval_status";--> statement-breakpoint
ALTER TABLE "image_uploads" ALTER COLUMN "approval_status" SET DEFAULT 'PENDING'::"public"."image_approval_status";--> statement-breakpoint
ALTER TABLE "image_uploads" ALTER COLUMN "approval_status" SET DATA TYPE "public"."image_approval_status" USING "approval_status"::"public"."image_approval_status";--> statement-breakpoint
ALTER TABLE "deals" ADD COLUMN "max_per_user" integer;--> statement-breakpoint
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_deal_id_deals_id_fk" FOREIGN KEY ("deal_id") REFERENCES "public"."deals"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "cart_items_user_idx" ON "cart_items" USING btree ("user_id");--> statement-breakpoint
CREATE UNIQUE INDEX "system_health_unresolved_per_entity" ON "system_health_findings" USING btree ("kind","entity_type","entity_id") WHERE resolved_at IS NULL;