20 lines
778 B
SQL
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);
|
|
|