ai-chatbot/lib/db/migrations_legacy/0021_add_generated_image.sql
Your Name 310dd115b2
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
chore(db): keep drizzle migrations folder journal-only
2026-02-14 01:30:51 +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);