From 305d4780ac945421a767f737a4a6ae0d13c989af Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 2 Jun 2026 18:47:31 -0400 Subject: [PATCH] fix(server): TestGcCloseStalePlayEvents seeds artist with sort_name The artists table requires sort_name (NOT NULL constraint added by 0009_artist_sort.up.sql). My GC integration test was inserting only name + relying on a separate SELECT to pull the id back, which both (a) violated the NOT NULL constraint and (b) was unnecessarily indirect. RETURNING the id directly is the standard pattern used everywhere else in the test suite. Test now matches the real-world insert pattern in api.search + library scan (sort_name mirrors name when no MBID-driven sort hint is available). Other GC tests in this file don't touch artists so they were already fine. --- internal/gc/worker_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/gc/worker_test.go b/internal/gc/worker_test.go index eb7ef9ee..5e5f737e 100644 --- a/internal/gc/worker_test.go +++ b/internal/gc/worker_test.go @@ -66,15 +66,13 @@ func TestGcCloseStalePlayEvents_ClosesOnly24hOldRows(t *testing.T) { // Need a track + session to satisfy FKs on play_events. var trackID pgtype.UUID - if err := pool.QueryRow(ctx, ` - INSERT INTO artists (name) VALUES ('A') RETURNING id - `).Scan(new(pgtype.UUID)); err != nil { - t.Fatalf("seed artist row: %v", err) - } - // Get the just-inserted artist id. var artistID pgtype.UUID - if err := pool.QueryRow(ctx, `SELECT id FROM artists WHERE name = 'A'`).Scan(&artistID); err != nil { - t.Fatalf("read artist: %v", err) + // `artists` has sort_name NOT NULL; mirror the title in sort_name + // like every real insert site does (see api.search / library scan). + if err := pool.QueryRow(ctx, ` + INSERT INTO artists (name, sort_name) VALUES ('A', 'A') RETURNING id + `).Scan(&artistID); err != nil { + t.Fatalf("seed artist row: %v", err) } var albumID pgtype.UUID if err := pool.QueryRow(ctx, `