nexus/packages/db/src/schema/chat_file_references.ts
Nexus Dev df88eaa56f feat(25-00): create chat_files and chat_file_references DB schema + migrations
- Add chatFiles Drizzle schema with companyId, conversationId, messageId, filename, mimeType, sizeBytes, objectKey, sha256, source, category, projectId columns
- Add chatFileReferences Drizzle schema for cross-conversation file references
- Add 0053_create_chat_files.sql migration with all columns, FKs, and indexes
- Add 0054_create_chat_file_references.sql migration with cascade deletes
- Export both tables from schema/index.ts
- Update _journal.json with entries for idx 53 and 54
2026-04-04 03:55:48 +00:00

20 lines
1,002 B
TypeScript

import { pgTable, uuid, timestamp, index } from "drizzle-orm/pg-core";
import { chatFiles } from "./chat_files.js";
import { chatConversations } from "./chat_conversations.js";
import { chatMessages } from "./chat_messages.js";
export const chatFileReferences = pgTable(
"chat_file_references",
{
id: uuid("id").primaryKey().defaultRandom(),
fileId: uuid("file_id").notNull().references(() => chatFiles.id, { onDelete: "cascade" }),
conversationId: uuid("conversation_id").notNull().references(() => chatConversations.id, { onDelete: "cascade" }),
messageId: uuid("message_id").references(() => chatMessages.id, { onDelete: "set null" }),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
},
(table) => ({
fileIdx: index("chat_file_refs_file_idx").on(table.fileId),
conversationIdx: index("chat_file_refs_conversation_idx").on(table.conversationId),
messageIdx: index("chat_file_refs_message_idx").on(table.messageId),
}),
);