diff --git a/internal/db/dbq/albums.sql.go b/internal/db/dbq/albums.sql.go index 37c4a3a7..e1772aa4 100644 --- a/internal/db/dbq/albums.sql.go +++ b/internal/db/dbq/albums.sql.go @@ -145,6 +145,14 @@ type GetAlbumCoverageRollupRow struct { // of pending; the UI surfaces it separately so operators can see how // many "pending" albums are blocked on missing MBID and won't be // helped by another scan. +// +// Invariant: with_art + pending + settled = total. (pending_no_mbid is +// not part of the sum — it's a subset of pending, surfaced separately.) +// +// The IN list below ('sidecar','embedded','mbcaa') must stay in sync +// with the cover_art_source CHECK constraint in migration +// 0016_album_cover_source.up.sql. If a new source value is added there +// without updating this query, with_art will silently undercount. func (q *Queries) GetAlbumCoverageRollup(ctx context.Context) (GetAlbumCoverageRollupRow, error) { row := q.db.QueryRow(ctx, getAlbumCoverageRollup) var i GetAlbumCoverageRollupRow diff --git a/internal/db/queries/albums.sql b/internal/db/queries/albums.sql index 0716205b..27930f3c 100644 --- a/internal/db/queries/albums.sql +++ b/internal/db/queries/albums.sql @@ -132,6 +132,14 @@ SELECT a.id AS album_id, -- of pending; the UI surfaces it separately so operators can see how -- many "pending" albums are blocked on missing MBID and won't be -- helped by another scan. +-- +-- Invariant: with_art + pending + settled = total. (pending_no_mbid is +-- not part of the sum — it's a subset of pending, surfaced separately.) +-- +-- The IN list below ('sidecar','embedded','mbcaa') must stay in sync +-- with the cover_art_source CHECK constraint in migration +-- 0016_album_cover_source.up.sql. If a new source value is added there +-- without updating this query, with_art will silently undercount. SELECT COUNT(*) AS total, COUNT(*) FILTER (WHERE cover_art_source IN ('sidecar','embedded','mbcaa')) AS with_art,