Files
minstrel/internal/db/migrations/0086_library_album_matches.up.sql
T
bvandeusenandClaude Opus 5.5 6028d78844
release / govulncheck (push) Successful in 17s
release / web (push) Successful in 1m33s
release / go (push) Successful in 1m49s
release / integration (push) Successful in 5m42s
release / android (push) Successful in 5m59s
release / Build signed APK (releases and dev) (push) Successful in 6m9s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 16s
release / Verify release artifacts (tag releases only) (push) Skipped
docs: migration headers keep the before and after, without ids, quotes or one library's numbers (#6277)
Applies rule 32's migration exception: each header still says what the
schema was, what changes and what it prevents, but task, milestone,
decision and rule ids are replaced by the practice they stood for, the
operator quotes by the decision, single-install counts are dropped, and
pointers to a deleted package and an external design doc are gone.
golang-migrate keeps no checksum, so editing applied migrations'
comments is safe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:34:39 -04:00

46 lines
2.5 KiB
SQL

-- Every library album is matched to MusicBrainz before it goes on the list, so
-- its metadata comes from MusicBrainz. 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;