Files
minstrel/internal/db/migrations/0029_tracks_mbid_nonunique.up.sql
T
bvandeusen e2432caa65 fix(library): extract recording MBID → tracks.mbid; unblock LB similarity
tracks.mbid was 100% NULL: the scanner only extracted album + artist
MBIDs, never the recording MBID. The ListenBrainz similarity worker is
gated on tracks.mbid IS NOT NULL, so track_similarity could never
populate — starving For-You/radio's strongest candidate source
(lb_similar) on every library.

- mbids.go: add extractRecordingMBID (mbz.Recording / Picard
  musicbrainz_recordingid). Separate fn so extractMBIDs' signature +
  unit tests stay untouched.
- scanner.go: persist recording MBID via UpsertTrack (heals on the
  file_path conflict, so re-scans backfill for free).
- BackfillTrackMBIDs: one-shot pass mirroring BackfillMBIDs, wired as
  scan Stage 2b (idempotent via SetTrackMbidIfNull, gated by
  BackfillCap, log-only progress).
- migration 0029: tracks_mbid_unique (0002, written when the column
  was always NULL) wrongly assumes one MBID == one track. A recording
  appears on multiple releases, so rows legitimately share a recording
  MBID. Replace with a non-unique partial index. Zero-risk: column is
  100% NULL at migration time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 13:49:38 -04:00

16 lines
841 B
SQL

-- tracks.mbid holds the MusicBrainz *recording* MBID — the id the
-- ListenBrainz similarity pipeline (ListPlayedTracksNeedingSimilarity,
-- GetTracksByMBIDs) matches on. A single recording legitimately appears
-- on multiple releases (album + compilation + single), so multiple
-- tracks rows share one recording MBID.
--
-- tracks_mbid_unique (added in 0002, when this column was always NULL
-- and never populated) wrongly assumes one MBID == one track. Now that
-- the scanner extracts the recording MBID, that uniqueness throws
-- 23505 for any recording present on >1 release. Replace it with a
-- non-unique partial index serving the same lookups. Zero-risk: the
-- column is 100% NULL at migration time.
DROP INDEX IF EXISTS tracks_mbid_unique;
CREATE INDEX IF NOT EXISTS tracks_mbid_idx ON tracks (mbid) WHERE mbid IS NOT NULL;