diff --git a/internal/db/migrations/0018_artist_art_and_provider_settings.down.sql b/internal/db/migrations/0018_artist_art_and_provider_settings.down.sql new file mode 100644 index 00000000..fae6f46c --- /dev/null +++ b/internal/db/migrations/0018_artist_art_and_provider_settings.down.sql @@ -0,0 +1,26 @@ +-- Reverse of 0018. + +ALTER TABLE scan_runs DROP COLUMN IF EXISTS artist_art_enrich; + +DROP TABLE IF EXISTS cover_art_sources_meta; +DROP TABLE IF EXISTS cover_art_provider_settings; + +ALTER TABLE artists DROP COLUMN IF EXISTS artist_art_sources_version; +ALTER TABLE albums DROP COLUMN IF EXISTS cover_art_sources_version; + +DROP INDEX IF EXISTS artists_artist_art_source_idx; +ALTER TABLE artists DROP CONSTRAINT IF EXISTS artists_artist_art_source_check; +ALTER TABLE artists DROP COLUMN IF EXISTS artist_art_source; +ALTER TABLE artists DROP COLUMN IF EXISTS artist_fanart_path; +ALTER TABLE artists DROP COLUMN IF EXISTS artist_thumb_path; + +-- Restore the original albums.cover_art_source CHECK from migration 0016. +ALTER TABLE albums DROP CONSTRAINT IF EXISTS albums_cover_art_source_check; +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')); +-- Note: rows with cover_art_source='theaudiodb' will be rejected by this +-- restored constraint. If down-migrating from a populated DB, run: +-- UPDATE albums SET cover_art_source = NULL WHERE cover_art_source = 'theaudiodb'; +-- before applying this migration. diff --git a/internal/db/migrations/0018_artist_art_and_provider_settings.up.sql b/internal/db/migrations/0018_artist_art_and_provider_settings.up.sql new file mode 100644 index 00000000..37dd3203 --- /dev/null +++ b/internal/db/migrations/0018_artist_art_and_provider_settings.up.sql @@ -0,0 +1,62 @@ +-- M7 cover-sources: schema for additional cover-art providers (TheAudioDB +-- as the v1 implementation), artist art (thumb + fanart), and the +-- recheck-on-source-change trigger. + +-- (0) Extend the existing albums.cover_art_source CHECK to accept the +-- new 'theaudiodb' value. The constraint was created in migration 0016 +-- with the IN list ('embedded','sidecar','mbcaa','none'); without this +-- extension, the enricher's UPDATE setting cover_art_source='theaudiodb' +-- would fail with a CHECK violation. +ALTER TABLE albums DROP CONSTRAINT IF EXISTS albums_cover_art_source_check; +ALTER TABLE albums + ADD CONSTRAINT albums_cover_art_source_check + CHECK (cover_art_source IS NULL + OR cover_art_source IN ('embedded','sidecar','mbcaa','theaudiodb','none')); + +-- (1) Artist art columns parallel albums.cover_art_*. +ALTER TABLE artists + ADD COLUMN artist_thumb_path text, + ADD COLUMN artist_fanart_path text, + ADD COLUMN artist_art_source text; + +ALTER TABLE artists + ADD CONSTRAINT artists_artist_art_source_check + CHECK (artist_art_source IS NULL + OR artist_art_source IN ('theaudiodb','none')); + +CREATE INDEX artists_artist_art_source_idx ON artists (artist_art_source); + +-- (2) Recheck-trigger version stamps. Default 0; current_version starts +-- at 1, so every existing row is "stale" relative to current — first +-- scan after migrate retries every settled row through the new chain. +ALTER TABLE albums + ADD COLUMN cover_art_sources_version int NOT NULL DEFAULT 0; +ALTER TABLE artists + ADD COLUMN artist_art_sources_version int NOT NULL DEFAULT 0; + +-- (3) Per-provider settings + singleton meta row. +CREATE TABLE cover_art_provider_settings ( + provider_id text PRIMARY KEY, + enabled boolean NOT NULL DEFAULT true, + api_key text, + display_order int NOT NULL DEFAULT 0, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE cover_art_sources_meta ( + id boolean PRIMARY KEY DEFAULT true, + current_version int NOT NULL DEFAULT 1, + CONSTRAINT cover_art_sources_meta_singleton CHECK (id = true) +); +INSERT INTO cover_art_sources_meta (id, current_version) VALUES (true, 1); + +-- Seed both v1 providers as enabled. TheAudioDB's api_key stays NULL; +-- the application supplies the test key '2' when the column is NULL, +-- per the no-coercive-settings principle. +INSERT INTO cover_art_provider_settings (provider_id, enabled, display_order) VALUES + ('mbcaa', true, 0), + ('theaudiodb', true, 1); + +-- (4) Scan-runs gains a stage tally column for artist art enrichment. +ALTER TABLE scan_runs ADD COLUMN artist_art_enrich jsonb;