CREATE TABLE "arena_votes" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "session_id" text NOT NULL, "response_id" text NOT NULL, "model_key" text NOT NULL, "criterion" text NOT NULL, "category" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "custom_endpoints" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "name" text NOT NULL, "base_url" text NOT NULL, "encrypted_key" text, "key_hint" text, "encrypted_headers" text, "models_path" text DEFAULT '/models' NOT NULL, "manual_models" jsonb DEFAULT '[]'::jsonb NOT NULL, "status" text DEFAULT 'unverified' NOT NULL, "last_validated_at" timestamp with time zone, "last_validation_error" text, "last_latency_ms" integer, "models_available" integer, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "project_files" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "project_id" text, "kind" text NOT NULL, "name" text NOT NULL, "mime_type" text NOT NULL, "size_bytes" integer NOT NULL, "data_base64" text NOT NULL, "width" integer, "height" integer, "estimated_tokens" integer, "description" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "projects" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "name" text NOT NULL, "description" text, "icon" text, "color" text, "instructions" text, "preferred_model_keys" jsonb DEFAULT '[]'::jsonb NOT NULL, "default_settings" jsonb DEFAULT '{}'::jsonb NOT NULL, "notes" text, "archived" boolean DEFAULT false NOT NULL, "sort_order" 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 ); --> statement-breakpoint CREATE TABLE "prompts" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "project_id" text, "kind" text DEFAULT 'user' NOT NULL, "name" text NOT NULL, "description" text, "content" text NOT NULL, "variables" jsonb DEFAULT '[]'::jsonb NOT NULL, "schema" jsonb, "folder" text, "tags" jsonb DEFAULT '[]'::jsonb NOT NULL, "favorite" boolean DEFAULT false NOT NULL, "default_model_key" text, "uses" integer DEFAULT 0 NOT NULL, "last_used_at" timestamp with time zone, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "shared_arena_sessions" ( "id" text PRIMARY KEY NOT NULL, "session_id" text NOT NULL, "user_id" text NOT NULL, "snapshot" jsonb NOT NULL, "is_public" boolean DEFAULT true NOT NULL, "view_count" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "revoked_at" timestamp with time zone ); --> statement-breakpoint CREATE TABLE "user_model_labels" ( "user_id" text NOT NULL, "model_key" text NOT NULL, "label" text NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "user_model_labels_user_id_model_key_pk" PRIMARY KEY("user_id","model_key") ); --> statement-breakpoint ALTER TABLE "conversations" ADD COLUMN "project_id" text;--> statement-breakpoint ALTER TABLE "arena_votes" ADD CONSTRAINT "arena_votes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "custom_endpoints" ADD CONSTRAINT "custom_endpoints_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project_files" ADD CONSTRAINT "project_files_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project_files" ADD CONSTRAINT "project_files_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "projects" ADD CONSTRAINT "projects_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "prompts" ADD CONSTRAINT "prompts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "prompts" ADD CONSTRAINT "prompts_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "shared_arena_sessions" ADD CONSTRAINT "shared_arena_sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "user_model_labels" ADD CONSTRAINT "user_model_labels_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint CREATE UNIQUE INDEX "arena_votes_session_criterion_uq" ON "arena_votes" USING btree ("session_id","criterion");--> statement-breakpoint CREATE INDEX "arena_votes_user_model_idx" ON "arena_votes" USING btree ("user_id","model_key");--> statement-breakpoint CREATE INDEX "custom_endpoints_user_idx" ON "custom_endpoints" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "project_files_user_idx" ON "project_files" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "project_files_project_idx" ON "project_files" USING btree ("project_id");--> statement-breakpoint CREATE INDEX "projects_user_idx" ON "projects" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "prompts_user_idx" ON "prompts" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "prompts_user_folder_idx" ON "prompts" USING btree ("user_id","folder");--> statement-breakpoint CREATE INDEX "shared_arena_session_idx" ON "shared_arena_sessions" USING btree ("session_id");--> statement-breakpoint CREATE INDEX "conversations_user_project_idx" ON "conversations" USING btree ("user_id","project_id");