- 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>
22 lines
1.1 KiB
TypeScript
22 lines
1.1 KiB
TypeScript
import { pgTable, uuid, text, timestamp, index } from "drizzle-orm/pg-core";
|
|
import { companies } from "./companies.js";
|
|
import { agents } from "./agents.js";
|
|
|
|
export const chatConversations = pgTable(
|
|
"chat_conversations",
|
|
{
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
companyId: uuid("company_id").notNull().references(() => companies.id),
|
|
title: text("title"),
|
|
agentId: uuid("agent_id").references(() => agents.id, { onDelete: "set null" }),
|
|
pinnedAt: timestamp("pinned_at", { withTimezone: true }),
|
|
archivedAt: timestamp("archived_at", { withTimezone: true }),
|
|
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
},
|
|
(table) => ({
|
|
companyUpdatedIdx: index("chat_conversations_company_updated_idx").on(table.companyId, table.updatedAt),
|
|
companyDeletedIdx: index("chat_conversations_company_deleted_idx").on(table.companyId, table.deletedAt),
|
|
}),
|
|
);
|