-- M7 #353: album cover origin attribution.
-- 'embedded'  — extracted from audio file (reserved for future slice).
-- 'sidecar'   — found in the album directory (cover.jpg/folder.jpg/etc).
-- 'mbcaa'     — fetched from MusicBrainz Cover Art Archive.
-- 'none'      — tried, no cover available. Skip auto-retry; only manual.
ALTER TABLE albums ADD COLUMN cover_art_source text;

ALTER TABLE albums
    ADD CONSTRAINT albums_cover_art_source_check
    CHECK (cover_art_source IS NULL
           OR cover_art_source IN ('embedded', 'sidecar', 'mbcaa', 'none'));

-- Backfill existing rows with cover_art_path set (defensive: scanner has
-- never populated cover_art_path in current dev, but keeps re-runs idempotent).
UPDATE albums SET cover_art_source = 'sidecar'
 WHERE cover_art_path IS NOT NULL AND cover_art_source IS NULL;

-- Index supports "find missing covers" queries.
CREATE INDEX albums_cover_art_source_idx ON albums (cover_art_source);
