- Add chat_conversations and chat_messages Drizzle schema tables - Generate migration 0047 with cascade FK and indexes - Add ChatConversation, ChatMessage, ChatConversationListResponse types - Add createConversationSchema, updateConversationSchema, createMessageSchema Zod validators - Implement chatService factory with CRUD, auto-title on first message, updatedAt bump - Add chat-service test suite (12 tests, all passing) Co-Authored-By: Paperclip <noreply@paperclip.ing>
17 lines
708 B
TypeScript
17 lines
708 B
TypeScript
import { pgTable, uuid, text, timestamp, index } from "drizzle-orm/pg-core";
|
|
import { chatConversations } from "./chat_conversations.js";
|
|
|
|
export const chatMessages = pgTable(
|
|
"chat_messages",
|
|
{
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
conversationId: uuid("conversation_id").notNull().references(() => chatConversations.id, { onDelete: "cascade" }),
|
|
role: text("role").notNull(),
|
|
content: text("content").notNull(),
|
|
agentId: uuid("agent_id"),
|
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
},
|
|
(table) => ({
|
|
conversationCreatedIdx: index("chat_messages_conversation_created_idx").on(table.conversationId, table.createdAt),
|
|
}),
|
|
);
|