feat(数据库): 添加对话分享表和迁移文件
- 新增 sharedConversations 表用于存储分享信息 - 支持分享短链接码、内容控制选项、浏览统计 - 添加选择性消息分享功能(selectedMessageIds) - 完善表关系定义和类型导出
This commit is contained in:
parent
6047af071c
commit
ea438eea72
18
src/drizzle/migrations/0013_charming_natasha_romanoff.sql
Normal file
18
src/drizzle/migrations/0013_charming_natasha_romanoff.sql
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
CREATE TABLE "shared_conversations" (
|
||||||
|
"id" serial PRIMARY KEY NOT NULL,
|
||||||
|
"share_id" varchar(64) NOT NULL,
|
||||||
|
"conversation_id" varchar(64) NOT NULL,
|
||||||
|
"user_id" varchar(64) NOT NULL,
|
||||||
|
"share_code" varchar(12) NOT NULL,
|
||||||
|
"title" varchar(255),
|
||||||
|
"description" text,
|
||||||
|
"include_thinking" boolean DEFAULT true,
|
||||||
|
"include_tool_calls" boolean DEFAULT false,
|
||||||
|
"include_images" boolean DEFAULT true,
|
||||||
|
"view_count" integer DEFAULT 0,
|
||||||
|
"is_active" boolean DEFAULT true,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now(),
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now(),
|
||||||
|
CONSTRAINT "shared_conversations_share_id_unique" UNIQUE("share_id"),
|
||||||
|
CONSTRAINT "shared_conversations_share_code_unique" UNIQUE("share_code")
|
||||||
|
);
|
||||||
1
src/drizzle/migrations/0014_naive_kronos.sql
Normal file
1
src/drizzle/migrations/0014_naive_kronos.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "shared_conversations" ADD COLUMN "snapshot_at" timestamp with time zone;
|
||||||
1323
src/drizzle/migrations/meta/0013_snapshot.json
Normal file
1323
src/drizzle/migrations/meta/0013_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1329
src/drizzle/migrations/meta/0014_snapshot.json
Normal file
1329
src/drizzle/migrations/meta/0014_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -92,6 +92,20 @@
|
|||||||
"when": 1766339459689,
|
"when": 1766339459689,
|
||||||
"tag": "0012_flippant_marvel_apes",
|
"tag": "0012_flippant_marvel_apes",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 13,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1766540812748,
|
||||||
|
"tag": "0013_charming_natasha_romanoff",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 14,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1766546111189,
|
||||||
|
"tag": "0014_naive_kronos",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -313,6 +313,40 @@ export const promptOptimizations = pgTable('prompt_optimizations', {
|
|||||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// 对话分享表
|
||||||
|
// ============================================
|
||||||
|
export const sharedConversations = pgTable('shared_conversations', {
|
||||||
|
id: serial('id').primaryKey(),
|
||||||
|
// 分享唯一标识
|
||||||
|
shareId: varchar('share_id', { length: 64 }).notNull().unique(),
|
||||||
|
// 关联对话
|
||||||
|
conversationId: varchar('conversation_id', { length: 64 }).notNull(),
|
||||||
|
// 分享创建者
|
||||||
|
userId: varchar('user_id', { length: 64 }).notNull(),
|
||||||
|
// 短链接码(用于分享 URL)
|
||||||
|
shareCode: varchar('share_code', { length: 12 }).notNull().unique(),
|
||||||
|
// 分享标题(可自定义)
|
||||||
|
title: varchar('title', { length: 255 }),
|
||||||
|
// 分享描述
|
||||||
|
description: text('description'),
|
||||||
|
// 内容控制
|
||||||
|
includeThinking: boolean('include_thinking').default(true),
|
||||||
|
includeToolCalls: boolean('include_tool_calls').default(false),
|
||||||
|
includeImages: boolean('include_images').default(true),
|
||||||
|
// 统计信息
|
||||||
|
viewCount: integer('view_count').default(0),
|
||||||
|
// 状态
|
||||||
|
isActive: boolean('is_active').default(true),
|
||||||
|
// 快照时间点(只显示此时间之前的消息)
|
||||||
|
snapshotAt: timestamp('snapshot_at', { withTimezone: true }),
|
||||||
|
// 选择的消息ID列表(JSON数组,null 表示全部消息)
|
||||||
|
selectedMessageIds: jsonb('selected_message_ids').$type<string[]>(),
|
||||||
|
// 时间戳
|
||||||
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
|
||||||
|
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(),
|
||||||
|
});
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 关系定义
|
// 关系定义
|
||||||
// ============================================
|
// ============================================
|
||||||
@ -399,6 +433,18 @@ export const notesRelations = relations(notes, ({ one }) => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// 分享关系
|
||||||
|
export const sharedConversationsRelations = relations(sharedConversations, ({ one }) => ({
|
||||||
|
user: one(users, {
|
||||||
|
fields: [sharedConversations.userId],
|
||||||
|
references: [users.userId],
|
||||||
|
}),
|
||||||
|
conversation: one(conversations, {
|
||||||
|
fields: [sharedConversations.conversationId],
|
||||||
|
references: [conversations.conversationId],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 类型定义
|
// 类型定义
|
||||||
// ============================================
|
// ============================================
|
||||||
@ -469,3 +515,6 @@ export type NewNote = typeof notes.$inferInsert;
|
|||||||
|
|
||||||
export type PromptOptimization = typeof promptOptimizations.$inferSelect;
|
export type PromptOptimization = typeof promptOptimizations.$inferSelect;
|
||||||
export type NewPromptOptimization = typeof promptOptimizations.$inferInsert;
|
export type NewPromptOptimization = typeof promptOptimizations.$inferInsert;
|
||||||
|
|
||||||
|
export type SharedConversation = typeof sharedConversations.$inferSelect;
|
||||||
|
export type NewSharedConversation = typeof sharedConversations.$inferInsert;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user