Files
minstrel/internal/db/migrations/0086_library_album_matches.up.sql
bvandeusenandClaude Opus 5.5 b887ab759b
release / govulncheck (push) Successful in 16s
release / web (push) Successful in 1m19s
release / go (push) Successful in 1m37s
release / integration (push) Successful in 5m28s
release / android (push) Successful in 5m44s
release / Build signed APK (releases and dev) (push) Successful in 5m58s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
fix: every library album is matched to MusicBrainz before it is listed, by its tags, its artist's discography or a search, and checked against its tracks (M502 #5569)
The one-time listing took only albums whose tags already named their
release group and artist, and left 340 off the list. The rest are now
matched: the release their tags name, else the artist's release groups
called what the album is called, else a MusicBrainz search by artist and
title. A group found by name is taken only when its tracks agree with the
album's (by disc and number, then title; length and title, or recording),
so a partial copy still matches and a same-titled other album does not.

library_album_matches records each album the listing decided, listed or
unmatched with why, so an album taken off the list is never re-listed. The
albums no match was found for are named on the Held tab. Album rows with
no tracks are no longer counted.

The length and title checks move from the importer to release, shared by
both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 17:16:05 -04:00

48 lines
2.6 KiB
SQL

-- Every library album is matched to MusicBrainz before it goes on the list
-- (#5569, operator 2026-10-10: "they should all exist in music brainz we
-- need to use their meta data or a search system to link them up"). The
-- listing in 0085 took only albums whose tags already named their release
-- group and artist; the rest are now matched by the release their tags
-- name, the artist's discography, or a search, and checked against their
-- own tracks.
--
-- library_album_matches one row per album the listing has decided:
-- listed (with how it was matched) or unmatched
-- (with why). It is the record that the listing
-- saw the album, so an album taken off the list
-- is never listed again.
CREATE TABLE library_album_matches (
album_id uuid PRIMARY KEY REFERENCES albums (id) ON DELETE CASCADE,
outcome text NOT NULL
CONSTRAINT library_album_matches_outcome_check CHECK (outcome IN ('listed', 'unmatched')),
-- tags its tags named the release group.
-- release its tags named a release; MusicBrainz named the group.
-- discography its title is one of the artist's release groups.
-- search MusicBrainz's search found it by artist and title.
method text NOT NULL DEFAULT ''
CONSTRAINT library_album_matches_method_check CHECK (method IN ('', 'tags', 'release', 'discography', 'search')),
release_group_mbid text NOT NULL DEFAULT '',
detail text NOT NULL DEFAULT '',
decided_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX library_album_matches_unmatched_idx ON library_album_matches (decided_at) WHERE outcome = 'unmatched';
-- The albums 0085's listing already took, by its own test, are decided:
-- one taken off the list since stays off.
INSERT INTO library_album_matches (album_id, outcome, method, release_group_mbid)
SELECT a.id, 'listed', 'tags', a.release_group_mbid
FROM albums a
JOIN artists ar ON ar.id = a.artist_id
JOIN acquisition_settings s ON s.id = true
WHERE s.library_listing_started_at IS NOT NULL
AND a.created_at <= s.library_listing_started_at
AND a.release_group_mbid IS NOT NULL AND a.release_group_mbid <> ''
AND ar.mbid IS NOT NULL AND ar.mbid <> ''
AND EXISTS (SELECT 1 FROM tracks t WHERE t.album_id = a.id);
-- The rest are matched by the wanted worker after boot: the listing resumes.
UPDATE acquisition_settings
SET library_listed_at = NULL, library_unlisted = 0
WHERE library_listing_started_at IS NOT NULL;