From db7c0c5c8b86580c44662694aabbb5b434643022 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 31 May 2026 03:52:10 +0700 Subject: [PATCH 1/2] feat(backfill): include artist_id in session migration This update modifies the `migrateRoom` function to include the `artist_id` when inserting a session. Additionally, the test suite for `migrateRoom` has been enhanced to verify that the `artist_id` is correctly passed to the `insertSession` function, ensuring that the migration process captures this important data point for each room. All related tests have been updated to reflect these changes. --- scripts/backfill/__tests__/migrateRoom.test.ts | 14 ++++++++++++++ scripts/backfill/migrateRoom.ts | 1 + 2 files changed, 15 insertions(+) diff --git a/scripts/backfill/__tests__/migrateRoom.test.ts b/scripts/backfill/__tests__/migrateRoom.test.ts index 40bd58ea..b1100ae5 100644 --- a/scripts/backfill/__tests__/migrateRoom.test.ts +++ b/scripts/backfill/__tests__/migrateRoom.test.ts @@ -77,6 +77,12 @@ describe("migrateRoom", () => { const stats = await migrateRoom(room, { dryRun: false }); expect(insertSession).toHaveBeenCalledTimes(1); + expect(insertSession).toHaveBeenCalledWith( + expect.objectContaining({ + account_id: "acc-1", + artist_id: null, + }), + ); expect(insertChat).toHaveBeenCalledTimes(1); // one batch call containing only the well-formed message expect(upsertChatMessages).toHaveBeenCalledTimes(1); @@ -102,6 +108,14 @@ describe("migrateRoom", () => { expect(insertChat).not.toHaveBeenCalled(); }); + it("passes room.artist_id into insertSession for straggler rooms", async () => { + await migrateRoom({ ...room, artist_id: "artist-1" }, { dryRun: false }); + + expect(insertSession).toHaveBeenCalledWith( + expect.objectContaining({ artist_id: "artist-1" }), + ); + }); + it("skips session/chat inserts when they already exist (idempotent re-run)", async () => { vi.mocked(selectSessions).mockResolvedValue([{ id: "s1" } as any]); diff --git a/scripts/backfill/migrateRoom.ts b/scripts/backfill/migrateRoom.ts index 79f8c192..66fa13d8 100644 --- a/scripts/backfill/migrateRoom.ts +++ b/scripts/backfill/migrateRoom.ts @@ -104,6 +104,7 @@ export async function migrateRoom( const session = await insertSession({ id: sessionId, account_id: room.account_id, + artist_id: room.artist_id, title, created_at: room.updated_at, updated_at: room.updated_at, From a3f728901740e8c0b1433b8c2b9efbf491291e51 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 31 May 2026 03:55:46 +0700 Subject: [PATCH 2/2] refactor(tests): streamline migrateRoom test assertions This commit refactors the `migrateRoom.test.ts` file by consolidating the assertion for the `insertSession` call to a single line, enhancing readability. The test now verifies that the `artist_id` is correctly passed to the `insertSession` function without altering the test's functionality. All related tests remain intact and pass successfully. --- scripts/backfill/__tests__/migrateRoom.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/backfill/__tests__/migrateRoom.test.ts b/scripts/backfill/__tests__/migrateRoom.test.ts index b1100ae5..5da4d8c9 100644 --- a/scripts/backfill/__tests__/migrateRoom.test.ts +++ b/scripts/backfill/__tests__/migrateRoom.test.ts @@ -111,9 +111,7 @@ describe("migrateRoom", () => { it("passes room.artist_id into insertSession for straggler rooms", async () => { await migrateRoom({ ...room, artist_id: "artist-1" }, { dryRun: false }); - expect(insertSession).toHaveBeenCalledWith( - expect.objectContaining({ artist_id: "artist-1" }), - ); + expect(insertSession).toHaveBeenCalledWith(expect.objectContaining({ artist_id: "artist-1" })); }); it("skips session/chat inserts when they already exist (idempotent re-run)", async () => {