ai-chatbot/lib/db/migrations/0066_add_ai_cad_workspace.sql
Your Name 413b5ffac1
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add AI-CAD workspace and KittyCAD integration
2026-04-06 14:46:51 +08:00

24 lines
1.1 KiB
SQL

CREATE TABLE IF NOT EXISTS "AiCadWorkspace" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"userId" uuid NOT NULL,
"prompt" text DEFAULT '' NOT NULL,
"generationProvider" varchar(32) DEFAULT 'kittycad-cad' NOT NULL,
"modelVersion" varchar(128) DEFAULT 'Turbo-v1.0-20250506' NOT NULL,
"viewerSettings" jsonb DEFAULT '{"envPreset":"studio","lightIntensity":1.1,"autoRotate":true,"showGrid":true,"wireframe":false}'::jsonb NOT NULL,
"messages" jsonb DEFAULT '[]'::jsonb NOT NULL,
"versions" jsonb DEFAULT '[]'::jsonb NOT NULL,
"activeVersionId" varchar(64),
"createdAt" timestamp DEFAULT now() NOT NULL,
"updatedAt" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "AiCadWorkspace_userId_unique" UNIQUE("userId")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "AiCadWorkspace" ADD CONSTRAINT "AiCadWorkspace_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "AiCadWorkspace_user_updated_idx"
ON "AiCadWorkspace"("userId", "updatedAt");