diff options
| author | Dhravya Shah <[email protected]> | 2024-06-22 20:38:00 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-22 20:38:00 -0500 |
| commit | 47e7528f675c187b0a771bc4040e8d8108c5ef8e (patch) | |
| tree | 0a738b7a816f7b61865558be567c88d86db238c3 /apps/web/server | |
| parent | delete packagelock (diff) | |
| parent | cleanup (diff) | |
| download | supermemory-47e7528f675c187b0a771bc4040e8d8108c5ef8e.tar.xz supermemory-47e7528f675c187b0a771bc4040e8d8108c5ef8e.zip | |
Merge pull request #79 from Dhravya/chathistory
addeed chathistory functionality
Diffstat (limited to 'apps/web/server')
| -rw-r--r-- | apps/web/server/db/schema.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/apps/web/server/db/schema.ts b/apps/web/server/db/schema.ts index 1ff23c82..f54d2094 100644 --- a/apps/web/server/db/schema.ts +++ b/apps/web/server/db/schema.ts @@ -154,3 +154,40 @@ export type StoredSpace = typeof space.$inferSelect; export type ChachedSpaceContent = StoredContent & { space: number; }; + +export const chatThreads = createTable( + "chatThread", + { + id: text("id") + .notNull() + .primaryKey() + .$defaultFn(() => crypto.randomUUID()), + firstMessage: text("firstMessage").notNull(), + userId: text("userId") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + }, + (thread) => ({ + userIdx: index("chatThread_user_idx").on(thread.userId), + }), +); + +export const chatHistory = createTable( + "chatHistory", + { + id: integer("id").notNull().primaryKey({ autoIncrement: true }), + threadId: text("threadId") + .notNull() + .references(() => chatThreads.id, { onDelete: "cascade" }), + question: text("question").notNull(), + answer: text("answerParts"), // Single answer part as string + answerSources: text("answerSources"), // JSON stringified array of objects + answerJustification: text("answerJustification"), + }, + (history) => ({ + threadIdx: index("chatHistory_thread_idx").on(history.threadId), + }), +); + +export type ChatThread = typeof chatThreads.$inferSelect; +export type ChatHistory = typeof chatHistory.$inferSelect; |