feat(数据库): 添加笔记表结构
- 新增 notes 表,存储用户笔记数据 - 支持标题、内容、标签等字段 - 关联对话和消息来源 - 添加置顶和归档状态
This commit is contained in:
parent
92ab731c62
commit
6d45e3575d
15
src/drizzle/migrations/0007_fantastic_molten_man.sql
Normal file
15
src/drizzle/migrations/0007_fantastic_molten_man.sql
Normal file
@ -0,0 +1,15 @@
|
||||
CREATE TABLE "notes" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"note_id" varchar(64) NOT NULL,
|
||||
"user_id" varchar(64) NOT NULL,
|
||||
"conversation_id" varchar(64),
|
||||
"message_id" varchar(64),
|
||||
"title" varchar(255) NOT NULL,
|
||||
"content" text NOT NULL,
|
||||
"tags" jsonb DEFAULT '[]'::jsonb,
|
||||
"is_pinned" boolean DEFAULT false,
|
||||
"is_archived" boolean DEFAULT false,
|
||||
"created_at" timestamp with time zone DEFAULT now(),
|
||||
"updated_at" timestamp with time zone DEFAULT now(),
|
||||
CONSTRAINT "notes_note_id_unique" UNIQUE("note_id")
|
||||
);
|
||||
1121
src/drizzle/migrations/meta/0007_snapshot.json
Normal file
1121
src/drizzle/migrations/meta/0007_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -50,6 +50,13 @@
|
||||
"when": 1766206123948,
|
||||
"tag": "0006_safe_spitfire",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "7",
|
||||
"when": 1766299055211,
|
||||
"tag": "0007_fantastic_molten_man",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -262,6 +262,31 @@ export const models = pgTable('models', {
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(),
|
||||
});
|
||||
|
||||
// ============================================
|
||||
// 笔记表
|
||||
// ============================================
|
||||
export const notes = pgTable('notes', {
|
||||
id: serial('id').primaryKey(),
|
||||
// 笔记唯一标识
|
||||
noteId: varchar('note_id', { length: 64 }).notNull().unique(),
|
||||
// 关联用户
|
||||
userId: varchar('user_id', { length: 64 }).notNull(),
|
||||
// 来源信息
|
||||
conversationId: varchar('conversation_id', { length: 64 }), // 来源对话
|
||||
messageId: varchar('message_id', { length: 64 }), // 来源消息
|
||||
// 笔记内容
|
||||
title: varchar('title', { length: 255 }).notNull(), // 标题
|
||||
content: text('content').notNull(), // 内容(Markdown)
|
||||
// 分类和标签
|
||||
tags: jsonb('tags').$type<string[]>().default([]), // 标签数组
|
||||
// 状态
|
||||
isPinned: boolean('is_pinned').default(false), // 置顶
|
||||
isArchived: boolean('is_archived').default(false), // 归档
|
||||
// 时间戳
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(),
|
||||
});
|
||||
|
||||
// ============================================
|
||||
// 关系定义
|
||||
// ============================================
|
||||
@ -332,6 +357,22 @@ export const messagesRelations = relations(messages, ({ one }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
// 笔记关系
|
||||
export const notesRelations = relations(notes, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [notes.userId],
|
||||
references: [users.userId],
|
||||
}),
|
||||
conversation: one(conversations, {
|
||||
fields: [notes.conversationId],
|
||||
references: [conversations.conversationId],
|
||||
}),
|
||||
message: one(messages, {
|
||||
fields: [notes.messageId],
|
||||
references: [messages.messageId],
|
||||
}),
|
||||
}));
|
||||
|
||||
// ============================================
|
||||
// 类型定义
|
||||
// ============================================
|
||||
@ -385,3 +426,6 @@ export type NewAssistant = typeof assistants.$inferInsert;
|
||||
|
||||
export type UserFavoriteAssistant = typeof userFavoriteAssistants.$inferSelect;
|
||||
export type NewUserFavoriteAssistant = typeof userFavoriteAssistants.$inferInsert;
|
||||
|
||||
export type Note = typeof notes.$inferSelect;
|
||||
export type NewNote = typeof notes.$inferInsert;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user