ai-chatbot/lib/db/migrations/0021_add_generated_image.sql
Your Name 53ddb7e585
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
Initial commit - clean repository
2025-12-17 20:15:18 +08:00

20 lines
778 B
SQL

-- 创建生成图片表
CREATE TABLE IF NOT EXISTS "GeneratedImage" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"userId" uuid NOT NULL REFERENCES "User"("id"),
"chatId" uuid REFERENCES "Chat"("id") ON DELETE CASCADE,
"messageId" uuid,
"thumbnailUrl" text NOT NULL,
"originalUrl" text NOT NULL,
"imageSize" varchar(10) DEFAULT '2K',
"prompt" text,
"modelId" varchar(128),
"createdAt" timestamp DEFAULT now() NOT NULL
);
-- 创建索引加速查询
CREATE INDEX IF NOT EXISTS "idx_generated_image_user" ON "GeneratedImage"("userId");
CREATE INDEX IF NOT EXISTS "idx_generated_image_created" ON "GeneratedImage"("createdAt" DESC);
CREATE INDEX IF NOT EXISTS "idx_generated_image_user_created" ON "GeneratedImage"("userId", "createdAt" DESC);