Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scripts/backfill/__tests__/migrateRoom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ describe("migrateRoom", () => {
expect(insertChat).toHaveBeenCalledTimes(1);
// one batch call containing only the well-formed message
expect(upsertChatMessages).toHaveBeenCalledTimes(1);
// `parts` stores the full UIMessage (matching the workflow's native
// persist path), not the bare parts array.
expect(upsertChatMessages).toHaveBeenCalledWith([
expect.objectContaining({ id: "m1", chat_id: "room-1", role: "user" }),
expect.objectContaining({
id: "m1",
chat_id: "room-1",
role: "user",
parts: { id: "m1", role: "user", parts: [{ type: "text", text: "hi" }] },
}),
]);
expect(stats.messagesWritten).toBe(1);
expect(stats.messagesMalformed).toBe(1);
Expand Down
7 changes: 6 additions & 1 deletion scripts/backfill/migrateRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ async function migrateMessages(
malformed++;
continue;
}
// The workflow persists the FULL UIMessage in the `parts` column
// (see lib/chat/persistLatestUserMessage / persistAssistantMessage),
// and the read path (getSessionChatHandler) returns `parts` verbatim
// expecting a UIMessage. Store the same shape so migrated history
// deserializes identically to natively-written chats.
rows.push({
id: memory.id,
chat_id: roomId,
role: content.role,
parts: content.parts,
parts: { id: memory.id, role: content.role, parts: content.parts },
created_at: memory.updated_at,
});
}
Expand Down
Loading