fix: release associations and add cleanup migration (#168)

* fix: release associations and add cleanup migration

* fix: incorrect test
This commit is contained in:
Gabe Farrell 2026-01-22 15:33:38 -05:00 committed by GitHub
parent 16cee8cfca
commit cb4d177875
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 106 additions and 26 deletions

View file

@ -62,7 +62,7 @@ func testDataForTracks(t *testing.T) {
VALUES (1, 1), (2, 2)`)
require.NoError(t, err)
// Associate tracks with artists
// Insert listens
err = store.Exec(context.Background(),
`INSERT INTO listens (user_id, track_id, listened_at)
VALUES (1, 1, NOW()), (1, 2, NOW())`)
@ -228,3 +228,27 @@ func TestDeleteTrack(t *testing.T) {
_, err = store.Count(ctx, `SELECT * FROM tracks WHERE id = 2`)
require.ErrorIs(t, err, pgx.ErrNoRows) // no rows error
}
func TestReleaseAssociations(t *testing.T) {
testDataForTracks(t)
ctx := context.Background()
track, err := store.SaveTrack(ctx, db.SaveTrackOpts{
Title: "Track Three",
AlbumID: 2,
ArtistIDs: []int32{2, 1}, // Artist Two feat. Artist One
Duration: 100,
})
require.NoError(t, err)
count, err := store.Count(ctx, `SELECT COUNT(*) FROM artist_releases WHERE release_id = 2`)
require.NoError(t, err)
require.Equal(t, 2, count, "expected release to be associated with artist from inserted track")
err = store.DeleteTrack(ctx, track.ID)
require.NoError(t, err)
count, err = store.Count(ctx, `SELECT COUNT(*) FROM artist_releases WHERE release_id = 2`)
require.NoError(t, err)
require.Equal(t, 1, count, "expected artist no longer on release to be disassociated from release")
}