feat(server/m7-379): heal existing artist+album mbid on rescan

This commit is contained in:
2026-05-04 19:03:12 -04:00
parent ab8fff834a
commit 6c6c4bc1e4
5 changed files with 82 additions and 0 deletions
+19
View File
@@ -515,6 +515,25 @@ func (q *Queries) SearchAlbums(ctx context.Context, arg SearchAlbumsParams) ([]A
return items, nil
}
const setAlbumMbidIfNull = `-- name: SetAlbumMbidIfNull :exec
UPDATE albums
SET mbid = $2,
updated_at = now()
WHERE id = $1 AND mbid IS NULL
`
type SetAlbumMbidIfNullParams struct {
ID pgtype.UUID
Mbid *string
}
// M7 #379: heal MBID on existing album rows during rescan. Idempotent —
// only updates when the existing mbid is NULL.
func (q *Queries) SetAlbumMbidIfNull(ctx context.Context, arg SetAlbumMbidIfNullParams) error {
_, err := q.db.Exec(ctx, setAlbumMbidIfNull, arg.ID, arg.Mbid)
return err
}
const upsertAlbum = `-- name: UpsertAlbum :one
INSERT INTO albums (title, sort_title, artist_id, release_date, mbid, cover_art_path)
VALUES ($1, $2, $3, $4, $5, $6)
+20
View File
@@ -327,6 +327,26 @@ func (q *Queries) SearchArtists(ctx context.Context, arg SearchArtistsParams) ([
return items, nil
}
const setArtistMbidIfNull = `-- name: SetArtistMbidIfNull :exec
UPDATE artists
SET mbid = $2,
updated_at = now()
WHERE id = $1 AND mbid IS NULL
`
type SetArtistMbidIfNullParams struct {
ID pgtype.UUID
Mbid *string
}
// M7 #379: heal MBID on existing artist rows during rescan. Idempotent —
// only updates when the existing mbid is NULL, so concurrent scans don't
// overwrite an existing value with a stale one.
func (q *Queries) SetArtistMbidIfNull(ctx context.Context, arg SetArtistMbidIfNullParams) error {
_, err := q.db.Exec(ctx, setArtistMbidIfNull, arg.ID, arg.Mbid)
return err
}
const upsertArtist = `-- name: UpsertArtist :one
INSERT INTO artists (name, sort_name, mbid)
VALUES ($1, $2, $3)
+8
View File
@@ -96,3 +96,11 @@ DELETE FROM albums a
WHERE a.id = $1
AND NOT EXISTS (SELECT 1 FROM tracks t WHERE t.album_id = a.id)
RETURNING a.id, a.artist_id;
-- name: SetAlbumMbidIfNull :exec
-- M7 #379: heal MBID on existing album rows during rescan. Idempotent —
-- only updates when the existing mbid is NULL.
UPDATE albums
SET mbid = $2,
updated_at = now()
WHERE id = $1 AND mbid IS NULL;
+9
View File
@@ -74,3 +74,12 @@ WHERE a.id = $1
AND NOT EXISTS (SELECT 1 FROM albums al WHERE al.artist_id = a.id)
AND NOT EXISTS (SELECT 1 FROM tracks t WHERE t.artist_id = a.id)
RETURNING a.id;
-- name: SetArtistMbidIfNull :exec
-- M7 #379: heal MBID on existing artist rows during rescan. Idempotent —
-- only updates when the existing mbid is NULL, so concurrent scans don't
-- overwrite an existing value with a stale one.
UPDATE artists
SET mbid = $2,
updated_at = now()
WHERE id = $1 AND mbid IS NULL;