CREATE TYPE "public"."comparison_status" AS ENUM('researching', 'completed', 'failed');--> statement-breakpoint CREATE TABLE "comparison_dimensions" ( "id" text PRIMARY KEY NOT NULL, "comparison_id" text NOT NULL, "name" text NOT NULL, "description" text, "weight" integer DEFAULT 1 NOT NULL, "order" integer DEFAULT 0 NOT NULL ); --> statement-breakpoint CREATE TABLE "comparison_items" ( "id" text PRIMARY KEY NOT NULL, "comparison_id" text NOT NULL, "name" text NOT NULL, "description" text, "image_url" text, "research_data" jsonb, "scores" jsonb, "pros" text[], "cons" text[], "order" integer DEFAULT 0 NOT NULL ); --> statement-breakpoint CREATE TABLE "comparisons" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "title" text NOT NULL, "query" text NOT NULL, "slug" text NOT NULL, "status" "comparison_status" DEFAULT 'researching' NOT NULL, "summary" text, "overall_data" jsonb, "tags" text[], "is_public" boolean DEFAULT true NOT NULL, "view_count" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "comparisons_slug_unique" UNIQUE("slug") ); --> statement-breakpoint CREATE TABLE "users" ( "id" text PRIMARY KEY NOT NULL, "name" text, "email" text NOT NULL, "email_verified" timestamp with time zone, "image" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "users_email_unique" UNIQUE("email") ); --> statement-breakpoint ALTER TABLE "comparison_dimensions" ADD CONSTRAINT "comparison_dimensions_comparison_id_comparisons_id_fk" FOREIGN KEY ("comparison_id") REFERENCES "public"."comparisons"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "comparison_items" ADD CONSTRAINT "comparison_items_comparison_id_comparisons_id_fk" FOREIGN KEY ("comparison_id") REFERENCES "public"."comparisons"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "comparisons" ADD CONSTRAINT "comparisons_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint CREATE INDEX "comparison_dimensions_comparison_id_idx" ON "comparison_dimensions" USING btree ("comparison_id");--> statement-breakpoint CREATE INDEX "comparison_items_comparison_id_idx" ON "comparison_items" USING btree ("comparison_id");--> statement-breakpoint CREATE INDEX "comparisons_user_id_idx" ON "comparisons" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "comparisons_slug_idx" ON "comparisons" USING btree ("slug");--> statement-breakpoint CREATE INDEX "comparisons_status_idx" ON "comparisons" USING btree ("status");