fix(25): handle missing chat_files table in listMessages and update addMessage test
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
eeaf6468a7
commit
939ebd6dc3
2 changed files with 16 additions and 12 deletions
|
|
@ -300,7 +300,7 @@ describe("chatService", () => {
|
|||
expect(insertChain.values).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ conversationId: "conv-1", role: "user", content: "Hi" }),
|
||||
);
|
||||
expect(result).toEqual(message);
|
||||
expect(result).toEqual({ ...message, files: [] });
|
||||
});
|
||||
|
||||
it("bumps conversation updatedAt after insert (Pitfall 3)", async () => {
|
||||
|
|
|
|||
|
|
@ -134,18 +134,22 @@ export function chatService(db: Db) {
|
|||
|
||||
// Load files for these messages and attach them
|
||||
const messageIds = items.map((m) => m.id);
|
||||
let filesByMessageId = new Map<string, typeof chatFiles.$inferSelect[]>();
|
||||
const filesByMessageId = new Map<string, typeof chatFiles.$inferSelect[]>();
|
||||
if (messageIds.length > 0) {
|
||||
const fileRows = await db
|
||||
.select()
|
||||
.from(chatFiles)
|
||||
.where(inArray(chatFiles.messageId, messageIds))
|
||||
.orderBy(asc(chatFiles.createdAt));
|
||||
for (const f of fileRows) {
|
||||
if (!f.messageId) continue;
|
||||
const existing = filesByMessageId.get(f.messageId) ?? [];
|
||||
existing.push(f);
|
||||
filesByMessageId.set(f.messageId, existing);
|
||||
try {
|
||||
const fileRows = await db
|
||||
.select()
|
||||
.from(chatFiles)
|
||||
.where(inArray(chatFiles.messageId, messageIds))
|
||||
.orderBy(asc(chatFiles.createdAt));
|
||||
for (const f of fileRows) {
|
||||
if (!f.messageId) continue;
|
||||
const existing = filesByMessageId.get(f.messageId) ?? [];
|
||||
existing.push(f);
|
||||
filesByMessageId.set(f.messageId, existing);
|
||||
}
|
||||
} catch {
|
||||
// chat_files table may not exist yet — treat as no files
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue