feat(db): fold every migration into one baseline at version 106
release / web (push) Successful in 1m13s
release / go (push) Successful in 1m48s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m56s
release / android (push) Successful in 4m19s
release / Build signed APK (push) Successful in 4m40s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
release / web (push) Successful in 1m13s
release / go (push) Successful in 1m48s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m56s
release / android (push) Successful in 4m19s
release / Build signed APK (push) Successful in 4m40s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
0106_baseline.up.sql is the schema at version 106 and the settings rows it starts with, taken from a database migrated through 0001–0106; a database built from the baseline alone dumps identically. A database already at 106 skips it. Comments that pointed at a migration number now name the table or constraint instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
-- Placeholder down migration — nothing to reverse.
|
||||
SELECT 1;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- Placeholder to establish the migration runner. Real schema lands in 0002.
|
||||
SELECT 1;
|
||||
@@ -1,5 +0,0 @@
|
||||
DROP TABLE IF EXISTS users;
|
||||
DROP TABLE IF EXISTS tracks;
|
||||
DROP TABLE IF EXISTS albums;
|
||||
DROP TABLE IF EXISTS artists;
|
||||
-- pgcrypto left installed; other extensions may depend on it.
|
||||
@@ -1,60 +0,0 @@
|
||||
-- Core library schema: artists, albums, tracks and users. Likes, sessions,
|
||||
-- scrobbling and similarity get tables of their own in later migrations.
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||
|
||||
CREATE TABLE artists (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name text NOT NULL,
|
||||
sort_name text NOT NULL,
|
||||
mbid text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE UNIQUE INDEX artists_mbid_unique ON artists (mbid) WHERE mbid IS NOT NULL;
|
||||
CREATE INDEX artists_sort_name ON artists (sort_name);
|
||||
|
||||
CREATE TABLE albums (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
title text NOT NULL,
|
||||
sort_title text NOT NULL,
|
||||
artist_id uuid NOT NULL REFERENCES artists (id) ON DELETE CASCADE,
|
||||
release_date date,
|
||||
mbid text,
|
||||
cover_art_path text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE UNIQUE INDEX albums_mbid_unique ON albums (mbid) WHERE mbid IS NOT NULL;
|
||||
CREATE INDEX albums_artist ON albums (artist_id);
|
||||
CREATE INDEX albums_sort_title ON albums (sort_title);
|
||||
|
||||
CREATE TABLE tracks (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
title text NOT NULL,
|
||||
album_id uuid NOT NULL REFERENCES albums (id) ON DELETE CASCADE,
|
||||
artist_id uuid NOT NULL REFERENCES artists (id) ON DELETE CASCADE,
|
||||
track_number integer,
|
||||
disc_number integer,
|
||||
duration_ms integer NOT NULL,
|
||||
file_path text NOT NULL UNIQUE,
|
||||
file_size bigint NOT NULL,
|
||||
file_format text NOT NULL,
|
||||
bitrate integer,
|
||||
mbid text,
|
||||
genre text,
|
||||
added_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE UNIQUE INDEX tracks_mbid_unique ON tracks (mbid) WHERE mbid IS NOT NULL;
|
||||
CREATE INDEX tracks_album ON tracks (album_id, disc_number, track_number);
|
||||
CREATE INDEX tracks_artist ON tracks (artist_id);
|
||||
|
||||
CREATE TABLE users (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
username text NOT NULL UNIQUE,
|
||||
password_hash text NOT NULL,
|
||||
api_token text NOT NULL UNIQUE,
|
||||
is_admin boolean NOT NULL DEFAULT false,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS subsonic_password;
|
||||
@@ -1,7 +0,0 @@
|
||||
-- Subsonic's token auth (t = md5(password + salt)) requires the server to
|
||||
-- compute md5 over the user's plaintext password. bcrypt (password_hash) is
|
||||
-- not reversible, so we store a *separate*, opt-in, plaintext credential used
|
||||
-- exclusively for the /rest/* legacy auth path. NULL means the user has not
|
||||
-- opted into Subsonic t/s auth and must use apiKey (OpenSubsonic) instead.
|
||||
|
||||
ALTER TABLE users ADD COLUMN subsonic_password text;
|
||||
@@ -1,2 +0,0 @@
|
||||
DROP INDEX IF EXISTS sessions_user_id_idx;
|
||||
DROP TABLE IF EXISTS sessions;
|
||||
@@ -1,17 +0,0 @@
|
||||
-- Session tokens authenticate /api/* requests. We store sha256(token) so a
|
||||
-- read-only DB leak doesn't grant active sessions; the raw token lives only
|
||||
-- in the client's cookie (web) or bearer header (native clients).
|
||||
--
|
||||
-- last_seen_at and user_agent (captured at issue time) are for an "active
|
||||
-- sessions" list.
|
||||
|
||||
CREATE TABLE sessions (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
token_hash bytea NOT NULL UNIQUE,
|
||||
user_agent text NOT NULL DEFAULT '',
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
last_seen_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX sessions_user_id_idx ON sessions (user_id);
|
||||
@@ -1,3 +0,0 @@
|
||||
DROP TABLE IF EXISTS skip_events;
|
||||
DROP TABLE IF EXISTS play_events;
|
||||
DROP TABLE IF EXISTS play_sessions;
|
||||
@@ -1,45 +0,0 @@
|
||||
-- Listening telemetry: play_sessions, play_events, skip_events.
|
||||
-- The table is named play_sessions (not sessions — that table already
|
||||
-- exists from migration 0004 and holds HTTP auth sessions). Listening
|
||||
-- sessions are an entirely separate concept.
|
||||
--
|
||||
-- session_vector_at_play is nullable: plays are recorded before the
|
||||
-- recommendation engine fills it.
|
||||
|
||||
CREATE TABLE play_sessions (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
started_at timestamptz NOT NULL,
|
||||
ended_at timestamptz,
|
||||
last_event_at timestamptz NOT NULL,
|
||||
track_count integer NOT NULL DEFAULT 0,
|
||||
client_id text
|
||||
);
|
||||
CREATE INDEX play_sessions_user_last_event_idx ON play_sessions (user_id, last_event_at DESC);
|
||||
|
||||
CREATE TABLE play_events (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
session_id uuid NOT NULL REFERENCES play_sessions(id) ON DELETE CASCADE,
|
||||
started_at timestamptz NOT NULL,
|
||||
ended_at timestamptz,
|
||||
duration_played_ms integer,
|
||||
completion_ratio double precision,
|
||||
was_skipped boolean NOT NULL DEFAULT false,
|
||||
client_id text,
|
||||
session_vector_at_play jsonb,
|
||||
scrobbled_at timestamptz
|
||||
);
|
||||
CREATE INDEX play_events_user_started_idx ON play_events (user_id, started_at DESC);
|
||||
CREATE INDEX play_events_user_track_idx ON play_events (user_id, track_id);
|
||||
|
||||
CREATE TABLE skip_events (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
session_id uuid NOT NULL REFERENCES play_sessions(id) ON DELETE CASCADE,
|
||||
skipped_at timestamptz NOT NULL,
|
||||
position_ms integer NOT NULL
|
||||
);
|
||||
CREATE INDEX skip_events_user_skipped_idx ON skip_events (user_id, skipped_at DESC);
|
||||
@@ -1,3 +0,0 @@
|
||||
DROP TABLE IF EXISTS general_likes_artists;
|
||||
DROP TABLE IF EXISTS general_likes_albums;
|
||||
DROP TABLE IF EXISTS general_likes;
|
||||
@@ -1,26 +0,0 @@
|
||||
-- Likes: three tables, one per entity type. general_likes was track-only;
|
||||
-- albums and artists get the same shape for Subsonic star/unstar.
|
||||
|
||||
CREATE TABLE general_likes (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
liked_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, track_id)
|
||||
);
|
||||
CREATE INDEX general_likes_user_liked_at_idx ON general_likes (user_id, liked_at DESC);
|
||||
|
||||
CREATE TABLE general_likes_albums (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
album_id uuid NOT NULL REFERENCES albums(id) ON DELETE CASCADE,
|
||||
liked_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, album_id)
|
||||
);
|
||||
CREATE INDEX general_likes_albums_user_liked_at_idx ON general_likes_albums (user_id, liked_at DESC);
|
||||
|
||||
CREATE TABLE general_likes_artists (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
artist_id uuid NOT NULL REFERENCES artists(id) ON DELETE CASCADE,
|
||||
liked_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, artist_id)
|
||||
);
|
||||
CREATE INDEX general_likes_artists_user_liked_at_idx ON general_likes_artists (user_id, liked_at DESC);
|
||||
@@ -1 +0,0 @@
|
||||
DROP TABLE IF EXISTS contextual_likes;
|
||||
@@ -1,28 +0,0 @@
|
||||
-- contextual_likes captures a per-session-context snapshot at the time of each
|
||||
-- like. The recommendation engine uses these rows to compute
|
||||
-- contextual_match_score per (current session, candidate track).
|
||||
--
|
||||
-- Multiple rows per (user, track) are allowed and expected — each row
|
||||
-- represents a like in a specific session context. Soft-deleted rows
|
||||
-- remain in the table (deleted_at populated) but are filtered out of the
|
||||
-- engine's queries via the partial index. Re-liking a previously-unliked
|
||||
-- track adds a NEW row (does not undelete the old one).
|
||||
|
||||
CREATE TABLE contextual_likes (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
liked_at timestamptz NOT NULL DEFAULT now(),
|
||||
deleted_at timestamptz,
|
||||
session_vector jsonb,
|
||||
session_id uuid REFERENCES play_sessions(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
-- Hot path for both the engine's lookups and the soft-delete UPDATE.
|
||||
CREATE INDEX contextual_likes_active_idx
|
||||
ON contextual_likes (user_id, track_id)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
-- For the engine's vector similarity queries.
|
||||
CREATE INDEX contextual_likes_vector_idx
|
||||
ON contextual_likes USING gin (session_vector);
|
||||
@@ -1,3 +0,0 @@
|
||||
DROP TABLE IF EXISTS scrobble_queue;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS listenbrainz_enabled;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS listenbrainz_token;
|
||||
@@ -1,26 +0,0 @@
|
||||
-- Outbound ListenBrainz scrobble worker.
|
||||
-- Per-user LB config (plaintext token; users rotate via /settings if leaked).
|
||||
-- scrobble_queue is a work list, not a log: successfully-sent rows are
|
||||
-- DELETEd by the worker (the canonical record stays in
|
||||
-- play_events.scrobbled_at). Only `pending` and `failed` states exist.
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN listenbrainz_token TEXT NULL,
|
||||
ADD COLUMN listenbrainz_enabled BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
CREATE TABLE scrobble_queue (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
play_event_id uuid NOT NULL REFERENCES play_events(id) ON DELETE CASCADE,
|
||||
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
next_attempt_at timestamptz NOT NULL DEFAULT now(),
|
||||
last_error TEXT NULL,
|
||||
enqueued_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (play_event_id)
|
||||
);
|
||||
|
||||
-- Hot path for the worker's per-tick query.
|
||||
CREATE INDEX scrobble_queue_pending_idx
|
||||
ON scrobble_queue (next_attempt_at)
|
||||
WHERE status = 'pending';
|
||||
@@ -1,2 +0,0 @@
|
||||
DROP TABLE IF EXISTS artist_similarity;
|
||||
DROP TABLE IF EXISTS track_similarity;
|
||||
@@ -1,33 +0,0 @@
|
||||
-- ListenBrainz similarity ingest. Two symmetric tables — tracks and
|
||||
-- artists — both keyed by (a_id, b_id, source) so the schema reserves room
|
||||
-- for additional similarity sources (musicbrainz_tag, user_cooccurrence)
|
||||
-- alongside listenbrainz. M4b only writes 'listenbrainz' rows.
|
||||
--
|
||||
-- The (a_id, score DESC) index satisfies M4c's hot path: "for seed S, give
|
||||
-- me top-N similar tracks/artists descending by score."
|
||||
|
||||
CREATE TABLE track_similarity (
|
||||
track_a_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
track_b_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
score DOUBLE PRECISION NOT NULL,
|
||||
source TEXT NOT NULL CHECK (source IN ('listenbrainz', 'musicbrainz_tag', 'user_cooccurrence')),
|
||||
fetched_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (track_a_id, track_b_id, source),
|
||||
CHECK (track_a_id <> track_b_id)
|
||||
);
|
||||
|
||||
CREATE INDEX track_similarity_a_score_idx
|
||||
ON track_similarity (track_a_id, score DESC);
|
||||
|
||||
CREATE TABLE artist_similarity (
|
||||
artist_a_id uuid NOT NULL REFERENCES artists(id) ON DELETE CASCADE,
|
||||
artist_b_id uuid NOT NULL REFERENCES artists(id) ON DELETE CASCADE,
|
||||
score DOUBLE PRECISION NOT NULL,
|
||||
source TEXT NOT NULL CHECK (source IN ('listenbrainz', 'musicbrainz_tag', 'user_cooccurrence')),
|
||||
fetched_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (artist_a_id, artist_b_id, source),
|
||||
CHECK (artist_a_id <> artist_b_id)
|
||||
);
|
||||
|
||||
CREATE INDEX artist_similarity_a_score_idx
|
||||
ON artist_similarity (artist_a_id, score DESC);
|
||||
@@ -1,8 +0,0 @@
|
||||
DROP INDEX IF EXISTS lidarr_requests_album_mbid_idx;
|
||||
DROP INDEX IF EXISTS lidarr_requests_artist_mbid_idx;
|
||||
DROP INDEX IF EXISTS lidarr_requests_status_idx;
|
||||
DROP INDEX IF EXISTS lidarr_requests_user_id_idx;
|
||||
DROP TABLE IF EXISTS lidarr_requests;
|
||||
DROP TYPE IF EXISTS lidarr_request_kind;
|
||||
DROP TYPE IF EXISTS lidarr_request_status;
|
||||
DROP TABLE IF EXISTS lidarr_config;
|
||||
@@ -1,63 +0,0 @@
|
||||
-- Lidarr integration. Two tables:
|
||||
--
|
||||
-- lidarr_config — singleton (CHECK id=1) holding the Lidarr
|
||||
-- connection. enabled=false is the unconfigured state.
|
||||
--
|
||||
-- lidarr_requests — per-request lifecycle row created by users at
|
||||
-- /discover, transitioned by admin at /admin/requests, and matched
|
||||
-- back to library tracks by the reconciler worker. Three matched_*_id
|
||||
-- FKs (one per kind) instead of polymorphic — clean SQL, ON DELETE
|
||||
-- SET NULL preserves audit even if the matched track is later removed.
|
||||
|
||||
CREATE TABLE lidarr_config (
|
||||
id smallint PRIMARY KEY DEFAULT 1 CHECK (id = 1),
|
||||
enabled boolean NOT NULL DEFAULT false,
|
||||
base_url text,
|
||||
api_key text,
|
||||
default_quality_profile_id int,
|
||||
default_root_folder_path text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
INSERT INTO lidarr_config (id, enabled) VALUES (1, false);
|
||||
|
||||
CREATE TYPE lidarr_request_status AS ENUM (
|
||||
'pending', 'approved', 'rejected', 'completed', 'failed'
|
||||
);
|
||||
CREATE TYPE lidarr_request_kind AS ENUM ('artist', 'album', 'track');
|
||||
|
||||
CREATE TABLE lidarr_requests (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
status lidarr_request_status NOT NULL DEFAULT 'pending',
|
||||
kind lidarr_request_kind NOT NULL,
|
||||
|
||||
lidarr_artist_mbid text NOT NULL,
|
||||
lidarr_album_mbid text,
|
||||
lidarr_track_mbid text,
|
||||
artist_name text NOT NULL,
|
||||
album_title text,
|
||||
track_title text,
|
||||
|
||||
quality_profile_id int,
|
||||
root_folder_path text,
|
||||
|
||||
decided_at timestamptz,
|
||||
decided_by uuid REFERENCES users(id) ON DELETE SET NULL,
|
||||
notes text,
|
||||
|
||||
completed_at timestamptz,
|
||||
matched_track_id uuid REFERENCES tracks(id) ON DELETE SET NULL,
|
||||
matched_album_id uuid REFERENCES albums(id) ON DELETE SET NULL,
|
||||
matched_artist_id uuid REFERENCES artists(id) ON DELETE SET NULL,
|
||||
|
||||
requested_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX lidarr_requests_user_id_idx ON lidarr_requests (user_id);
|
||||
CREATE INDEX lidarr_requests_status_idx ON lidarr_requests (status);
|
||||
CREATE INDEX lidarr_requests_artist_mbid_idx ON lidarr_requests (lidarr_artist_mbid);
|
||||
CREATE INDEX lidarr_requests_album_mbid_idx ON lidarr_requests (lidarr_album_mbid)
|
||||
WHERE lidarr_album_mbid IS NOT NULL;
|
||||
@@ -1,7 +0,0 @@
|
||||
DROP INDEX IF EXISTS lidarr_quarantine_actions_created_idx;
|
||||
DROP INDEX IF EXISTS lidarr_quarantine_actions_track_idx;
|
||||
DROP TABLE IF EXISTS lidarr_quarantine_actions;
|
||||
DROP TYPE IF EXISTS lidarr_quarantine_action_kind;
|
||||
DROP INDEX IF EXISTS lidarr_quarantine_track_idx;
|
||||
DROP TABLE IF EXISTS lidarr_quarantine;
|
||||
DROP TYPE IF EXISTS lidarr_quarantine_reason;
|
||||
@@ -1,48 +0,0 @@
|
||||
-- Per-user track quarantines + admin action audit log.
|
||||
--
|
||||
-- lidarr_quarantine — one row per (user, track) complaint. PK matches
|
||||
-- the general_likes pattern. Re-flagging the same track upserts. Deleted
|
||||
-- on user resolution (un-hide), admin Resolve, or any of the deletes.
|
||||
--
|
||||
-- lidarr_quarantine_actions — audit log of admin destructive actions.
|
||||
-- Snapshot text columns let the log stay readable after the underlying
|
||||
-- track/album rows are gone.
|
||||
|
||||
CREATE TYPE lidarr_quarantine_reason AS ENUM (
|
||||
'bad_rip', 'wrong_file', 'wrong_tags', 'duplicate', 'other'
|
||||
);
|
||||
|
||||
CREATE TABLE lidarr_quarantine (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
reason lidarr_quarantine_reason NOT NULL,
|
||||
notes text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, track_id)
|
||||
);
|
||||
|
||||
-- Only the track_id index is non-redundant: the composite PK
|
||||
-- (user_id, track_id) already serves WHERE user_id = $1 lookups, so a
|
||||
-- separate (user_id, created_at DESC) index would just amplify writes
|
||||
-- without paying for itself at household-scale row counts.
|
||||
CREATE INDEX lidarr_quarantine_track_idx ON lidarr_quarantine (track_id);
|
||||
|
||||
CREATE TYPE lidarr_quarantine_action_kind AS ENUM (
|
||||
'resolved', 'deleted_file', 'deleted_via_lidarr'
|
||||
);
|
||||
|
||||
CREATE TABLE lidarr_quarantine_actions (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
track_id uuid NOT NULL,
|
||||
track_title text NOT NULL,
|
||||
artist_name text NOT NULL,
|
||||
album_title text,
|
||||
action lidarr_quarantine_action_kind NOT NULL,
|
||||
admin_id uuid REFERENCES users(id) ON DELETE SET NULL,
|
||||
lidarr_album_mbid text,
|
||||
affected_users int NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX lidarr_quarantine_actions_track_idx ON lidarr_quarantine_actions (track_id);
|
||||
CREATE INDEX lidarr_quarantine_actions_created_idx ON lidarr_quarantine_actions (created_at DESC);
|
||||
@@ -1,2 +0,0 @@
|
||||
DROP INDEX IF EXISTS artist_similarity_unmatched_seed_score_idx;
|
||||
DROP TABLE IF EXISTS artist_similarity_unmatched;
|
||||
@@ -1,17 +0,0 @@
|
||||
-- Persist unmatched-similar-artist MBIDs that the M4b worker would
|
||||
-- otherwise discard. Mirrors artist_similarity shape: same composite PK
|
||||
-- with source, same (seed_id, score DESC) index, same source enum check.
|
||||
-- The candidate side is text + name (no FK) — that's the whole point.
|
||||
|
||||
CREATE TABLE artist_similarity_unmatched (
|
||||
seed_artist_id uuid NOT NULL REFERENCES artists(id) ON DELETE CASCADE,
|
||||
candidate_mbid text NOT NULL,
|
||||
candidate_name text NOT NULL,
|
||||
score DOUBLE PRECISION NOT NULL,
|
||||
source text NOT NULL CHECK (source IN ('listenbrainz', 'musicbrainz_tag', 'user_cooccurrence')),
|
||||
fetched_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (seed_artist_id, candidate_mbid, source)
|
||||
);
|
||||
|
||||
CREATE INDEX artist_similarity_unmatched_seed_score_idx
|
||||
ON artist_similarity_unmatched (seed_artist_id, score DESC);
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE lidarr_config
|
||||
DROP COLUMN default_metadata_profile_id;
|
||||
@@ -1,8 +0,0 @@
|
||||
-- Persist the chosen Lidarr metadata profile alongside quality profile +
|
||||
-- root folder. Lidarr POST /api/v1/artist requires metadataProfileId;
|
||||
-- without storing it every Approve would refetch and pick the first.
|
||||
-- Nullable: existing rows get NULL and the service falls back to "fetch
|
||||
-- list and pick first" until an admin saves.
|
||||
|
||||
ALTER TABLE lidarr_config
|
||||
ADD COLUMN default_metadata_profile_id integer;
|
||||
@@ -1,2 +0,0 @@
|
||||
DROP TABLE IF EXISTS playlist_tracks;
|
||||
DROP TABLE IF EXISTS playlists;
|
||||
@@ -1,38 +0,0 @@
|
||||
-- User playlists.
|
||||
|
||||
CREATE TABLE playlists (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name text NOT NULL,
|
||||
description text NOT NULL DEFAULT '',
|
||||
is_public boolean NOT NULL DEFAULT false,
|
||||
cover_path text,
|
||||
track_count integer NOT NULL DEFAULT 0,
|
||||
duration_sec integer NOT NULL DEFAULT 0,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX playlists_user_idx ON playlists (user_id, updated_at DESC);
|
||||
CREATE INDEX playlists_public_idx ON playlists (is_public, updated_at DESC) WHERE is_public;
|
||||
|
||||
-- track_id is nullable + ON DELETE SET NULL so deleting a track from
|
||||
-- the library doesn't silently drop entries from operators' playlists.
|
||||
-- Denormalized title/artist/album/duration carry a snapshot so the row
|
||||
-- is still legible after the upstream track row is gone.
|
||||
CREATE TABLE playlist_tracks (
|
||||
playlist_id uuid NOT NULL REFERENCES playlists(id) ON DELETE CASCADE,
|
||||
position integer NOT NULL,
|
||||
track_id uuid REFERENCES tracks(id) ON DELETE SET NULL,
|
||||
title text NOT NULL,
|
||||
artist_name text NOT NULL,
|
||||
album_title text NOT NULL,
|
||||
duration_sec integer NOT NULL,
|
||||
added_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (playlist_id, position)
|
||||
);
|
||||
|
||||
-- Partial index supports the FK lookup that fires when a track is
|
||||
-- deleted (ON DELETE SET NULL) — without it, deleting a track triggers
|
||||
-- a full scan of playlist_tracks.
|
||||
CREATE INDEX playlist_tracks_track_idx ON playlist_tracks (track_id) WHERE track_id IS NOT NULL;
|
||||
@@ -1,10 +0,0 @@
|
||||
DROP TABLE IF EXISTS system_playlist_runs;
|
||||
DROP INDEX IF EXISTS playlists_user_kind_idx;
|
||||
ALTER TABLE playlists
|
||||
DROP CONSTRAINT IF EXISTS playlists_seed_consistent;
|
||||
ALTER TABLE playlists
|
||||
DROP CONSTRAINT IF EXISTS playlists_kind_variant_consistent;
|
||||
ALTER TABLE playlists
|
||||
DROP COLUMN IF EXISTS seed_artist_id,
|
||||
DROP COLUMN IF EXISTS system_variant,
|
||||
DROP COLUMN IF EXISTS kind;
|
||||
@@ -1,46 +0,0 @@
|
||||
-- System-generated playlists.
|
||||
-- Adds kind/system_variant/seed_artist_id columns to playlists and a
|
||||
-- per-user run-tracking table. Backfills existing playlists to
|
||||
-- kind='user'.
|
||||
|
||||
-- Discriminator on existing playlists table.
|
||||
ALTER TABLE playlists
|
||||
ADD COLUMN kind text NOT NULL DEFAULT 'user',
|
||||
ADD COLUMN system_variant text,
|
||||
ADD COLUMN seed_artist_id uuid REFERENCES artists(id) ON DELETE SET NULL;
|
||||
|
||||
-- Belt-and-braces backfill in case the DEFAULT didn't apply on some
|
||||
-- runtime branches; a no-op when the column metadata already filled.
|
||||
UPDATE playlists SET kind = 'user' WHERE kind IS NULL OR kind = '';
|
||||
|
||||
-- Constraint: kind/system_variant pair is consistent.
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_kind_variant_consistent
|
||||
CHECK (
|
||||
(kind = 'user' AND system_variant IS NULL)
|
||||
OR
|
||||
(kind = 'system' AND system_variant IN ('for_you', 'songs_like_artist'))
|
||||
);
|
||||
|
||||
-- Constraint: 'songs_like_artist' has a seed artist; nothing else does.
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_seed_consistent
|
||||
CHECK (
|
||||
(system_variant IS NULL AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'for_you' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'songs_like_artist' AND seed_artist_id IS NOT NULL)
|
||||
);
|
||||
|
||||
-- Filter index for kind=user vs kind=system queries on the user's row.
|
||||
CREATE INDEX playlists_user_kind_idx ON playlists (user_id, kind);
|
||||
|
||||
-- Per-user run tracking — one row per user.
|
||||
CREATE TABLE system_playlist_runs (
|
||||
user_id uuid PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||
last_run_at timestamptz,
|
||||
last_run_date date,
|
||||
in_flight boolean NOT NULL DEFAULT false,
|
||||
last_error text
|
||||
);
|
||||
@@ -1,3 +0,0 @@
|
||||
DROP INDEX IF EXISTS albums_cover_art_source_idx;
|
||||
ALTER TABLE albums DROP CONSTRAINT IF EXISTS albums_cover_art_source_check;
|
||||
ALTER TABLE albums DROP COLUMN IF EXISTS cover_art_source;
|
||||
@@ -1,19 +0,0 @@
|
||||
-- Album cover origin attribution.
|
||||
-- 'embedded' — extracted from audio file (reserved).
|
||||
-- '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);
|
||||
@@ -1,2 +0,0 @@
|
||||
DROP INDEX IF EXISTS scan_runs_started_at_idx;
|
||||
DROP TABLE IF EXISTS scan_runs;
|
||||
@@ -1,20 +0,0 @@
|
||||
-- Track library-scan / MBID-backfill / cover-enrich runs so the
|
||||
-- admin overview can show last-run results + manual trigger state.
|
||||
CREATE TABLE scan_runs (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
started_at timestamptz NOT NULL DEFAULT now(),
|
||||
finished_at timestamptz,
|
||||
-- Per-stage tallies are jsonb so the schema doesn't need to grow when
|
||||
-- a stage gains/loses a counter. Each stage's value matches the Go
|
||||
-- struct emitted by that worker (e.g. library.Stats).
|
||||
library jsonb,
|
||||
mbid_backfill jsonb,
|
||||
cover_enrich jsonb,
|
||||
-- Non-empty when the run as a whole errored (a stage panic, or the
|
||||
-- worker hit a fatal error before writing stage tallies).
|
||||
error_message text
|
||||
);
|
||||
|
||||
-- The status endpoint always reads the latest row; the in-flight guard
|
||||
-- needs to find rows where finished_at IS NULL. Both hit started_at DESC.
|
||||
CREATE INDEX scan_runs_started_at_idx ON scan_runs (started_at DESC);
|
||||
@@ -1,26 +0,0 @@
|
||||
-- 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.
|
||||
@@ -1,61 +0,0 @@
|
||||
-- Schema for additional cover-art providers (TheAudioDB first), 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;
|
||||
@@ -1 +0,0 @@
|
||||
DROP TABLE IF EXISTS scan_schedule;
|
||||
@@ -1,23 +0,0 @@
|
||||
-- Recurring scans: singleton table holding the scan schedule
|
||||
-- config. mode is the discriminator: 'off' / 'interval' / 'daily' / 'weekly'.
|
||||
-- Per-mode fields are populated only when their mode is selected; others
|
||||
-- stay NULL. weekly_day uses ISO 8601: 1=Monday … 7=Sunday.
|
||||
CREATE TABLE scan_schedule (
|
||||
id boolean PRIMARY KEY DEFAULT true,
|
||||
mode text NOT NULL DEFAULT 'off',
|
||||
interval_hours int,
|
||||
time_of_day text,
|
||||
weekly_day int,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT scan_schedule_singleton CHECK (id = true),
|
||||
CONSTRAINT scan_schedule_mode_check
|
||||
CHECK (mode IN ('off', 'interval', 'daily', 'weekly')),
|
||||
CONSTRAINT scan_schedule_interval_check
|
||||
CHECK (mode != 'interval' OR (interval_hours IS NOT NULL AND interval_hours > 0)),
|
||||
CONSTRAINT scan_schedule_daily_check
|
||||
CHECK (mode != 'daily' OR time_of_day IS NOT NULL),
|
||||
CONSTRAINT scan_schedule_weekly_check
|
||||
CHECK (mode != 'weekly' OR (time_of_day IS NOT NULL AND weekly_day IS NOT NULL AND weekly_day BETWEEN 1 AND 7))
|
||||
);
|
||||
|
||||
INSERT INTO scan_schedule (id) VALUES (true);
|
||||
@@ -1,18 +0,0 @@
|
||||
-- Restore the prior tighter CHECK constraints (pre-Deezer/Last.fm).
|
||||
-- This will fail if any rows currently have artist_art_source =
|
||||
-- 'deezer' or 'lastfm' (likewise album); operator must clear those
|
||||
-- rows manually before rolling back.
|
||||
|
||||
ALTER TABLE artists DROP CONSTRAINT IF EXISTS artists_artist_art_source_check;
|
||||
ALTER TABLE artists
|
||||
ADD CONSTRAINT artists_artist_art_source_check
|
||||
CHECK (artist_art_source IS NULL
|
||||
OR artist_art_source IN ('theaudiodb','none'));
|
||||
|
||||
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'));
|
||||
|
||||
ALTER TABLE cover_art_sources_meta DROP COLUMN IF EXISTS last_registered_providers_hash;
|
||||
@@ -1,22 +0,0 @@
|
||||
-- Relax cover-art and artist-art source CHECK constraints so the new
|
||||
-- Deezer and Last.fm providers can persist their IDs as
|
||||
-- accepted source values. Also add the
|
||||
-- last_registered_providers_hash column to cover_art_sources_meta for
|
||||
-- boot-time auto-bump detection (when the registered-provider set
|
||||
-- changes, we bump current_version once so 'none' rows get
|
||||
-- re-eligibled).
|
||||
|
||||
ALTER TABLE artists DROP CONSTRAINT IF EXISTS artists_artist_art_source_check;
|
||||
ALTER TABLE artists
|
||||
ADD CONSTRAINT artists_artist_art_source_check
|
||||
CHECK (artist_art_source IS NULL
|
||||
OR artist_art_source IN ('theaudiodb','deezer','lastfm','none'));
|
||||
|
||||
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','deezer','lastfm','none'));
|
||||
|
||||
ALTER TABLE cover_art_sources_meta
|
||||
ADD COLUMN IF NOT EXISTS last_registered_providers_hash text NOT NULL DEFAULT '';
|
||||
@@ -1,21 +0,0 @@
|
||||
-- Restore the prior tighter CHECK constraints (pre-discover).
|
||||
-- This will fail if any rows currently have system_variant = 'discover';
|
||||
-- operator must clear those rows manually before rolling back.
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_kind_variant_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_kind_variant_consistent CHECK (
|
||||
(kind = 'user' AND system_variant IS NULL)
|
||||
OR
|
||||
(kind = 'system' AND system_variant IN ('for_you', 'songs_like_artist'))
|
||||
);
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_seed_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_seed_consistent CHECK (
|
||||
(system_variant IS NULL AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'for_you' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'songs_like_artist' AND seed_artist_id IS NOT NULL)
|
||||
);
|
||||
@@ -1,27 +0,0 @@
|
||||
-- Adds 'discover' as an accepted system_variant alongside 'for_you'
|
||||
-- and 'songs_like_artist'. Discover has no seed_artist_id (like
|
||||
-- for_you), so the variant->seed coherence check is extended to
|
||||
-- accept (system_variant = 'discover' AND seed_artist_id IS NULL).
|
||||
--
|
||||
-- Drops + re-adds both CHECK constraints; PostgreSQL doesn't have
|
||||
-- ALTER CONSTRAINT for CHECK so this is the standard pattern.
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_kind_variant_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_kind_variant_consistent CHECK (
|
||||
(kind = 'user' AND system_variant IS NULL)
|
||||
OR
|
||||
(kind = 'system' AND system_variant IN ('for_you', 'songs_like_artist', 'discover'))
|
||||
);
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_seed_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_seed_consistent CHECK (
|
||||
(system_variant IS NULL AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'for_you' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'discover' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'songs_like_artist' AND seed_artist_id IS NOT NULL)
|
||||
);
|
||||
@@ -1,9 +0,0 @@
|
||||
-- Reverses migration 0022. Drop tables in reverse dependency order.
|
||||
-- This will fail if any rows in audit_log or user_invites reference
|
||||
-- users that were deleted with ON DELETE SET NULL semantics; those
|
||||
-- references will already be NULL so the drops should succeed cleanly.
|
||||
|
||||
DROP TABLE IF EXISTS audit_log;
|
||||
DROP TABLE IF EXISTS user_invites;
|
||||
DROP TABLE IF EXISTS registration_settings;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS display_name;
|
||||
@@ -1,48 +0,0 @@
|
||||
-- User management:
|
||||
--
|
||||
-- - users.display_name: optional human-readable name distinct from username.
|
||||
-- - user_invites: admin-generated tokens; user redeems during signup.
|
||||
-- - registration_settings (singleton): controls whether registration is
|
||||
-- 'invite_only' (default after first admin) or 'open' (admin can
|
||||
-- re-enable). The registration handler also has a special-case for the
|
||||
-- "no users yet" state where it ignores invites and lets the first
|
||||
-- register as admin.
|
||||
-- - audit_log: append-only record of admin-driven user mutations.
|
||||
-- No retention policy.
|
||||
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS display_name text;
|
||||
|
||||
CREATE TABLE user_invites (
|
||||
token text PRIMARY KEY,
|
||||
invited_by uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
note text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
expires_at timestamptz NOT NULL,
|
||||
redeemed_at timestamptz,
|
||||
redeemed_by uuid REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE INDEX user_invites_active_idx
|
||||
ON user_invites (expires_at)
|
||||
WHERE redeemed_at IS NULL;
|
||||
|
||||
CREATE TABLE registration_settings (
|
||||
id boolean PRIMARY KEY DEFAULT true,
|
||||
mode text NOT NULL DEFAULT 'invite_only',
|
||||
CONSTRAINT registration_settings_singleton CHECK (id = true),
|
||||
CONSTRAINT registration_settings_mode_check
|
||||
CHECK (mode IN ('invite_only', 'open'))
|
||||
);
|
||||
INSERT INTO registration_settings (id) VALUES (true)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
CREATE TABLE audit_log (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
actor_id uuid REFERENCES users(id) ON DELETE SET NULL,
|
||||
target_id uuid REFERENCES users(id) ON DELETE SET NULL,
|
||||
action text NOT NULL,
|
||||
metadata jsonb,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX audit_log_created_at_idx ON audit_log (created_at DESC);
|
||||
CREATE INDEX audit_log_actor_id_idx ON audit_log (actor_id);
|
||||
CREATE INDEX audit_log_target_id_idx ON audit_log (target_id);
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS auto_approve_requests;
|
||||
@@ -1,8 +0,0 @@
|
||||
-- Adds users.auto_approve_requests for the per-user auto-approve toggle:
|
||||
-- the request submission flow approves that user's requests at once.
|
||||
--
|
||||
-- Default false: existing users keep manual approval, opt-in via the
|
||||
-- admin user-management UI.
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS auto_approve_requests boolean NOT NULL DEFAULT false;
|
||||
@@ -1,4 +0,0 @@
|
||||
DROP TABLE IF EXISTS password_resets;
|
||||
DROP TABLE IF EXISTS smtp_config;
|
||||
DROP INDEX IF EXISTS users_email_unique;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS email;
|
||||
@@ -1,44 +0,0 @@
|
||||
-- User management U3: self-service profile + email + email-based
|
||||
-- password reset infrastructure.
|
||||
--
|
||||
-- - users.email: optional; required for the forgot-password flow.
|
||||
-- Lowercase-unique via a partial index to allow many NULL emails
|
||||
-- while preventing case-insensitive duplicates.
|
||||
-- - smtp_config singleton: SMTP server settings + from-address +
|
||||
-- enabled flag. The actual mailer reads this row at send time so
|
||||
-- config edits take effect without a server restart.
|
||||
-- - password_resets: short-lived single-use tokens for the
|
||||
-- forgot-password flow. 24h TTL enforced at issue time.
|
||||
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS email text;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS users_email_unique
|
||||
ON users (lower(email))
|
||||
WHERE email IS NOT NULL;
|
||||
|
||||
CREATE TABLE smtp_config (
|
||||
id boolean PRIMARY KEY DEFAULT true,
|
||||
enabled boolean NOT NULL DEFAULT false,
|
||||
host text NOT NULL DEFAULT '',
|
||||
port int NOT NULL DEFAULT 587,
|
||||
username text NOT NULL DEFAULT '',
|
||||
password text NOT NULL DEFAULT '',
|
||||
from_address text NOT NULL DEFAULT '',
|
||||
from_name text NOT NULL DEFAULT 'Minstrel',
|
||||
use_tls boolean NOT NULL DEFAULT true,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT smtp_config_singleton CHECK (id = true)
|
||||
);
|
||||
INSERT INTO smtp_config (id) VALUES (true)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
CREATE TABLE password_resets (
|
||||
token text PRIMARY KEY,
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
expires_at timestamptz NOT NULL,
|
||||
used_at timestamptz
|
||||
);
|
||||
CREATE INDEX password_resets_user_id_idx ON password_resets (user_id);
|
||||
CREATE INDEX password_resets_active_idx
|
||||
ON password_resets (expires_at)
|
||||
WHERE used_at IS NULL;
|
||||
@@ -1 +0,0 @@
|
||||
DROP TABLE IF EXISTS library_changes;
|
||||
@@ -1,20 +0,0 @@
|
||||
-- Append-only change log for library entities. Every mutation on
|
||||
-- artists/albums/tracks/likes/playlists/playlist_tracks writes a row
|
||||
-- in the same transaction as the mutation itself. Powers the delta-sync
|
||||
-- endpoint — clients pass back the last-seen `id` as a cursor.
|
||||
--
|
||||
-- Retention: not capped here. A cursor older than what the table keeps gets
|
||||
-- the reset path (410).
|
||||
|
||||
CREATE TABLE library_changes (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
entity_type TEXT NOT NULL CHECK (entity_type IN (
|
||||
'artist', 'album', 'track', 'like_track', 'like_album', 'like_artist',
|
||||
'playlist', 'playlist_track'
|
||||
)),
|
||||
entity_id TEXT NOT NULL,
|
||||
op TEXT NOT NULL CHECK (op IN ('upsert', 'delete')),
|
||||
changed_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_library_changes_id ON library_changes(id);
|
||||
@@ -1,3 +0,0 @@
|
||||
ALTER TABLE users
|
||||
DROP COLUMN timezone,
|
||||
DROP COLUMN timezone_updated_at;
|
||||
@@ -1,8 +0,0 @@
|
||||
-- 0026_users_timezone.up.sql — per-user timezone for the system-playlist
|
||||
-- scheduler. Default 'UTC' so existing rows + brand-new
|
||||
-- users have a safe value before their first client check-in via
|
||||
-- PUT /api/me/timezone. The scheduler reads this column to decide
|
||||
-- which IANA zone to anchor each user's daily 03:00 build to.
|
||||
ALTER TABLE users
|
||||
ADD COLUMN timezone text NOT NULL DEFAULT 'UTC',
|
||||
ADD COLUMN timezone_updated_at timestamptz;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- 0027_system_playlist_rotation.down.sql
|
||||
DROP TABLE IF EXISTS system_playlist_rotation_state;
|
||||
|
||||
ALTER TABLE play_events
|
||||
DROP COLUMN IF EXISTS source;
|
||||
@@ -1,26 +0,0 @@
|
||||
-- 0027_system_playlist_rotation.up.sql — sample-history dedup for
|
||||
-- system playlists. Two parts:
|
||||
--
|
||||
-- 1. play_events.source: which system playlist a play originated
|
||||
-- from ('for_you' | 'discover' | future kinds), or NULL for any
|
||||
-- play not launched from a system-playlist surface (library,
|
||||
-- user playlist, radio, Subsonic). Lets the ingest path know a
|
||||
-- play should count against that playlist's rotation.
|
||||
--
|
||||
-- 2. system_playlist_rotation_state: per (user, playlist_kind) set
|
||||
-- of track ids already played in the current rotation window.
|
||||
-- Shuffle-on-play prefers the unplayed tail; when the snapshot
|
||||
-- is exhausted the set resets and rotation_started_at advances.
|
||||
-- Centralized server-side so phone / web / watch share one
|
||||
-- rotation, mirroring how radio dedup already lives server-side.
|
||||
ALTER TABLE play_events
|
||||
ADD COLUMN source text;
|
||||
|
||||
CREATE TABLE system_playlist_rotation_state (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
playlist_kind text NOT NULL,
|
||||
played_track_ids uuid[] NOT NULL DEFAULT '{}',
|
||||
rotation_started_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, playlist_kind)
|
||||
);
|
||||
@@ -1,24 +0,0 @@
|
||||
-- Reverts to the 0021 constraint set (for_you, songs_like_artist,
|
||||
-- discover only). Fails if any playlists row still has one of the
|
||||
-- five new system_variant values — delete/rebuild system playlists
|
||||
-- first if rolling back.
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_kind_variant_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_kind_variant_consistent CHECK (
|
||||
(kind = 'user' AND system_variant IS NULL)
|
||||
OR
|
||||
(kind = 'system' AND system_variant IN ('for_you', 'songs_like_artist', 'discover'))
|
||||
);
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_seed_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_seed_consistent CHECK (
|
||||
(system_variant IS NULL AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'for_you' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'discover' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'songs_like_artist' AND seed_artist_id IS NOT NULL)
|
||||
);
|
||||
@@ -1,45 +0,0 @@
|
||||
-- Before: the five discovery mixes (deep_cuts, rediscover, new_for_you,
|
||||
-- on_this_day, first_listens) had producers and registry entries but no
|
||||
-- system_variant values in the two playlists CHECK constraints, so inserting
|
||||
-- any of them failed playlists_kind_variant_consistent (SQLSTATE 23514) —
|
||||
-- and because BuildSystemPlaylists is one all-or-nothing transaction, that
|
||||
-- aborts the WHOLE build. After: the constraints accept them.
|
||||
--
|
||||
-- All five are seedless (like for_you/discover): seed_artist_id IS
|
||||
-- NULL. Drop + re-add both constraints with the expanded set, same
|
||||
-- pattern as 0021_discover_variant (Postgres has no ALTER CONSTRAINT
|
||||
-- for CHECK).
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_kind_variant_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_kind_variant_consistent CHECK (
|
||||
(kind = 'user' AND system_variant IS NULL)
|
||||
OR
|
||||
(kind = 'system' AND system_variant IN (
|
||||
'for_you', 'songs_like_artist', 'discover',
|
||||
'deep_cuts', 'rediscover', 'new_for_you',
|
||||
'on_this_day', 'first_listens'
|
||||
))
|
||||
);
|
||||
|
||||
ALTER TABLE playlists DROP CONSTRAINT IF EXISTS playlists_seed_consistent;
|
||||
ALTER TABLE playlists
|
||||
ADD CONSTRAINT playlists_seed_consistent CHECK (
|
||||
(system_variant IS NULL AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'for_you' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'discover' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'deep_cuts' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'rediscover' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'new_for_you' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'on_this_day' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'first_listens' AND seed_artist_id IS NULL)
|
||||
OR
|
||||
(system_variant = 'songs_like_artist' AND seed_artist_id IS NOT NULL)
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
-- Reverts to the unique partial index. This FAILS if any recording
|
||||
-- MBID is shared across releases in the library (the exact case 0029
|
||||
-- exists to allow) — dedupe tracks.mbid before rolling back.
|
||||
|
||||
DROP INDEX IF EXISTS tracks_mbid_idx;
|
||||
CREATE UNIQUE INDEX tracks_mbid_unique ON tracks (mbid) WHERE mbid IS NOT NULL;
|
||||
@@ -1,15 +0,0 @@
|
||||
-- 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;
|
||||
@@ -1,15 +0,0 @@
|
||||
-- Restore the 0020 fixed-allowlist CHECKs. FAILS if any row holds a
|
||||
-- source value outside the allowlist (the exact case 0030 enables) —
|
||||
-- normalise such rows before rolling back.
|
||||
|
||||
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','deezer','lastfm','none'));
|
||||
|
||||
ALTER TABLE artists DROP CONSTRAINT IF EXISTS artists_artist_art_source_check;
|
||||
ALTER TABLE artists
|
||||
ADD CONSTRAINT artists_artist_art_source_check
|
||||
CHECK (artist_art_source IS NULL
|
||||
OR artist_art_source IN ('theaudiodb','deezer','lastfm','none'));
|
||||
@@ -1,18 +0,0 @@
|
||||
-- The cover/artist art `*_source` column stores the recording
|
||||
-- provider's registry ID. coverart.Register makes the provider set
|
||||
-- extensible, so a fixed IN-list CHECK (0016 → 0018 → 0020) required a
|
||||
-- schema migration for every new provider and rejected any
|
||||
-- out-of-list value (e.g. test stub providers): a fixed-value CHECK
|
||||
-- fighting an extensible value set. Relax to "NULL or any
|
||||
-- non-empty string" — the registry, not the schema, is the source of
|
||||
-- truth for valid provider IDs.
|
||||
|
||||
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 <> '');
|
||||
|
||||
ALTER TABLE artists DROP CONSTRAINT IF EXISTS artists_artist_art_source_check;
|
||||
ALTER TABLE artists
|
||||
ADD CONSTRAINT artists_artist_art_source_check
|
||||
CHECK (artist_art_source IS NULL OR artist_art_source <> '');
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE lidarr_requests
|
||||
DROP COLUMN lidarr_add_confirmed_at;
|
||||
@@ -1,8 +0,0 @@
|
||||
-- Additive: records when Lidarr accepted the add (POST artist/album)
|
||||
-- for an approved request. NULL = not yet sent/confirmed; the
|
||||
-- reconciler idempotently (re)sends the add until this is set, then
|
||||
-- watches for the import. Decouples the durable admin approval from the
|
||||
-- best-effort Lidarr call, so a transient Lidarr outage does not force a
|
||||
-- manual re-approve.
|
||||
ALTER TABLE lidarr_requests
|
||||
ADD COLUMN lidarr_add_confirmed_at timestamptz;
|
||||
@@ -1 +0,0 @@
|
||||
DROP TABLE IF EXISTS playback_errors;
|
||||
@@ -1,41 +0,0 @@
|
||||
-- Client-reported playback errors. Populated by clients when a track
|
||||
-- fails to play (zero duration, decode error, etc.); surfaced in the
|
||||
-- admin /admin/playback-errors inbox so an admin can hide / delete
|
||||
-- / re-request the offending track.
|
||||
--
|
||||
-- resolved_at + resolved_by + resolution are NULL until an admin acts
|
||||
-- on the row. Auto-resolved by the client when the admin clicks Hide /
|
||||
-- Delete / Re-request from the inbox row, with the resolution string
|
||||
-- recording which path was taken. The partial index keeps the
|
||||
-- unresolved-queue lookup fast even as resolved history accumulates.
|
||||
--
|
||||
-- CHECK constraints on kind/resolution gate the enum values so client
|
||||
-- typos can't pollute the data; a new value means swapping the constraint
|
||||
-- in the same migration as the code that writes it.
|
||||
|
||||
CREATE TABLE playback_errors (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
client_id text NOT NULL,
|
||||
kind text NOT NULL,
|
||||
detail text,
|
||||
occurred_at timestamptz NOT NULL DEFAULT now(),
|
||||
resolved_at timestamptz,
|
||||
resolved_by uuid REFERENCES users(id),
|
||||
resolution text,
|
||||
CONSTRAINT playback_errors_kind_check
|
||||
CHECK (kind IN ('zero_duration', 'load_failed', 'stalled')),
|
||||
CONSTRAINT playback_errors_resolution_check
|
||||
CHECK (resolution IS NULL OR resolution IN
|
||||
('hidden', 'deleted', 'requested', 'fixed', 'ignored')),
|
||||
CONSTRAINT playback_errors_resolved_consistency
|
||||
CHECK ((resolved_at IS NULL) = (resolution IS NULL))
|
||||
);
|
||||
|
||||
CREATE INDEX idx_playback_errors_unresolved
|
||||
ON playback_errors (occurred_at DESC)
|
||||
WHERE resolved_at IS NULL;
|
||||
|
||||
CREATE INDEX idx_playback_errors_track
|
||||
ON playback_errors (track_id);
|
||||
@@ -1,21 +0,0 @@
|
||||
-- Recreate the scan_schedule singleton (mirror of 0019) so the drop is
|
||||
-- reversible. The application no longer reads or writes this table.
|
||||
CREATE TABLE scan_schedule (
|
||||
id boolean PRIMARY KEY DEFAULT true,
|
||||
mode text NOT NULL DEFAULT 'off',
|
||||
interval_hours int,
|
||||
time_of_day text,
|
||||
weekly_day int,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT scan_schedule_singleton CHECK (id = true),
|
||||
CONSTRAINT scan_schedule_mode_check
|
||||
CHECK (mode IN ('off', 'interval', 'daily', 'weekly')),
|
||||
CONSTRAINT scan_schedule_interval_check
|
||||
CHECK (mode != 'interval' OR (interval_hours IS NOT NULL AND interval_hours > 0)),
|
||||
CONSTRAINT scan_schedule_daily_check
|
||||
CHECK (mode != 'daily' OR time_of_day IS NOT NULL),
|
||||
CONSTRAINT scan_schedule_weekly_check
|
||||
CHECK (mode != 'weekly' OR (time_of_day IS NOT NULL AND weekly_day IS NOT NULL AND weekly_day BETWEEN 1 AND 7))
|
||||
);
|
||||
|
||||
INSERT INTO scan_schedule (id) VALUES (true);
|
||||
@@ -1,4 +0,0 @@
|
||||
-- Retire the configurable scan scheduler. New-file pickup is now handled by
|
||||
-- the fsnotify watcher + a hardcoded safety-net delta walk (cmd/minstrel),
|
||||
-- so the configurable schedule (and its admin UI) is gone.
|
||||
DROP TABLE IF EXISTS scan_schedule;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- Reverse 0034_you_might_like.up.sql.
|
||||
DROP TABLE IF EXISTS you_might_like_artists;
|
||||
DROP TABLE IF EXISTS you_might_like_albums;
|
||||
@@ -1,36 +0,0 @@
|
||||
-- 0034_you_might_like.up.sql — "You might like" Home rows.
|
||||
--
|
||||
-- Per-user ranked lists of IN-LIBRARY albums/artists the listener
|
||||
-- doesn't actively spin but is predicted to enjoy, derived from the
|
||||
-- same similarity + like-weighted candidate engine that powers For-You
|
||||
-- (rolled up from track scores to album/artist). Built in the daily
|
||||
-- 3am BuildSystemPlaylists pass and atomic-replaced, exactly like the
|
||||
-- system playlists; read back by /api/home.
|
||||
--
|
||||
-- Two thin tables (id + rank) rather than denormalized snapshots: the
|
||||
-- Home read path hydrates album/artist refs through the existing
|
||||
-- albums/artists joins, so a later metadata edit is reflected without
|
||||
-- a rebuild. CASCADE on user/album/artist deletes keeps them clean.
|
||||
|
||||
CREATE TABLE you_might_like_albums (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
album_id uuid NOT NULL REFERENCES albums(id) ON DELETE CASCADE,
|
||||
rank integer NOT NULL,
|
||||
built_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, album_id)
|
||||
);
|
||||
|
||||
-- Read path orders by rank within a user; the index serves it directly.
|
||||
CREATE INDEX you_might_like_albums_user_rank_idx
|
||||
ON you_might_like_albums (user_id, rank);
|
||||
|
||||
CREATE TABLE you_might_like_artists (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
artist_id uuid NOT NULL REFERENCES artists(id) ON DELETE CASCADE,
|
||||
rank integer NOT NULL,
|
||||
built_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, artist_id)
|
||||
);
|
||||
|
||||
CREATE INDEX you_might_like_artists_user_rank_idx
|
||||
ON you_might_like_artists (user_id, rank);
|
||||
@@ -1,3 +0,0 @@
|
||||
-- Reverse 0035_taste_profile.up.sql.
|
||||
DROP TABLE IF EXISTS taste_profile_tags;
|
||||
DROP TABLE IF EXISTS taste_profile_artists;
|
||||
@@ -1,33 +0,0 @@
|
||||
-- 0035_taste_profile.up.sql — per-user taste profile.
|
||||
--
|
||||
-- A persistent, decaying model of each user's taste, rebuilt daily from
|
||||
-- graded play engagement (completion + skip position) plus explicit
|
||||
-- likes. Two facet tables: weighted artists and weighted genre tags.
|
||||
-- Weight is a signed float — positive = drawn to, negative = (passively)
|
||||
-- avoided; magnitude reflects decayed engagement. Candidate sourcing and
|
||||
-- scoring read them.
|
||||
--
|
||||
-- CASCADE on user/artist deletes keeps them clean. Indexed by
|
||||
-- (user_id, weight DESC) to serve "top taste artists/tags" reads cheaply.
|
||||
|
||||
CREATE TABLE taste_profile_artists (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
artist_id uuid NOT NULL REFERENCES artists(id) ON DELETE CASCADE,
|
||||
weight double precision NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, artist_id)
|
||||
);
|
||||
|
||||
CREATE INDEX taste_profile_artists_user_weight_idx
|
||||
ON taste_profile_artists (user_id, weight DESC);
|
||||
|
||||
CREATE TABLE taste_profile_tags (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
tag text NOT NULL,
|
||||
weight double precision NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, tag)
|
||||
);
|
||||
|
||||
CREATE INDEX taste_profile_tags_user_weight_idx
|
||||
ON taste_profile_tags (user_id, weight DESC);
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS debug_mode_enabled;
|
||||
DROP TABLE IF EXISTS diagnostic_events;
|
||||
@@ -1,54 +0,0 @@
|
||||
-- Device diagnostics / debug-reporting subsystem.
|
||||
--
|
||||
-- When an account has users.debug_mode_enabled = true, that account's
|
||||
-- client(s) stream a timeseries of device state here: connectivity +
|
||||
-- server-health transitions (roaming / poor-data recovery), UPnP/Sonos
|
||||
-- sync events (locked-phone desync), and power/lifecycle state (Doze /
|
||||
-- battery-optimization, the prime suspect for the desync). The admin
|
||||
-- /admin/diagnostics view filters by account + device + time window and
|
||||
-- exports the slice as JSON for offline analysis.
|
||||
--
|
||||
-- `kind` is a COARSE category gated by a CHECK whitelist; the finer event
|
||||
-- discriminator + all event-specific fields live in the `payload` jsonb. This
|
||||
-- keeps the enum small and stable so new event variants don't require a
|
||||
-- migration (only a new *category* would: a new CHECK value means swapping the
|
||||
-- constraint in the same migration). If you add a category here, mirror it in
|
||||
-- the handler whitelist in internal/api/diagnostics.go.
|
||||
--
|
||||
-- Two timestamps on purpose: occurred_at is the client device clock
|
||||
-- (when the event happened on the phone — may be skewed/wrong, e.g. in
|
||||
-- a dead zone), received_at is the server clock at ingest. Retention
|
||||
-- pruning is keyed on received_at so a bad client clock can't keep rows
|
||||
-- alive forever.
|
||||
|
||||
CREATE TABLE diagnostic_events (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
client_id text NOT NULL,
|
||||
app_version text,
|
||||
os_version text,
|
||||
kind text NOT NULL,
|
||||
payload jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||
occurred_at timestamptz NOT NULL,
|
||||
received_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT diagnostic_events_kind_check
|
||||
CHECK (kind IN (
|
||||
'connectivity', 'upnp_sync', 'power', 'lifecycle',
|
||||
'heartbeat', 'http'
|
||||
))
|
||||
);
|
||||
|
||||
-- Admin reads filter by account then device, ordered newest-first.
|
||||
CREATE INDEX idx_diagnostic_events_user
|
||||
ON diagnostic_events (user_id, occurred_at DESC);
|
||||
CREATE INDEX idx_diagnostic_events_client
|
||||
ON diagnostic_events (client_id, occurred_at DESC);
|
||||
-- Retention pruner deletes by server-clock age.
|
||||
CREATE INDEX idx_diagnostic_events_received
|
||||
ON diagnostic_events (received_at);
|
||||
|
||||
-- Per-account opt-in for diagnostics reporting. Admin-set primarily
|
||||
-- (flip remotely while a bug is live); the client also exposes a local
|
||||
-- OFF switch. Default false: no account reports until explicitly enabled.
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS debug_mode_enabled boolean NOT NULL DEFAULT false;
|
||||
@@ -1,9 +0,0 @@
|
||||
-- Drop rows using the new value first so they don't violate the restored
|
||||
-- (narrower) constraint, then revert the whitelist.
|
||||
DELETE FROM diagnostic_events WHERE kind = 'playback';
|
||||
ALTER TABLE diagnostic_events DROP CONSTRAINT diagnostic_events_kind_check;
|
||||
ALTER TABLE diagnostic_events ADD CONSTRAINT diagnostic_events_kind_check
|
||||
CHECK (kind IN (
|
||||
'connectivity', 'upnp_sync', 'power', 'lifecycle',
|
||||
'heartbeat', 'http'
|
||||
));
|
||||
@@ -1,19 +0,0 @@
|
||||
-- Add 'playback' to the diagnostic_events kind whitelist.
|
||||
--
|
||||
-- `route` and `player_state` events fire for EVERY output route (phone
|
||||
-- speaker, Bluetooth, UPnP/Sonos), so bucketing them under 'upnp_sync'
|
||||
-- was misleading — a listener on Bluetooth earbuds produced "upnp_sync"
|
||||
-- rows. 'upnp_sync' now means genuinely UPnP/Sonos-specific signal
|
||||
-- (drops, and future resync/desync); general playback + route telemetry
|
||||
-- moves to the new 'playback' kind.
|
||||
--
|
||||
-- The new value lands by dropping and re-adding the constraint in the same
|
||||
-- migration. Existing rows tagged
|
||||
-- 'upnp_sync' stay as-is (debug telemetry on a 30-day retention).
|
||||
|
||||
ALTER TABLE diagnostic_events DROP CONSTRAINT diagnostic_events_kind_check;
|
||||
ALTER TABLE diagnostic_events ADD CONSTRAINT diagnostic_events_kind_check
|
||||
CHECK (kind IN (
|
||||
'connectivity', 'upnp_sync', 'power', 'lifecycle',
|
||||
'heartbeat', 'http', 'playback'
|
||||
));
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE play_events DROP COLUMN pick_kind;
|
||||
ALTER TABLE playlist_tracks DROP COLUMN pick_kind;
|
||||
@@ -1,34 +0,0 @@
|
||||
-- For You exploration attribution.
|
||||
--
|
||||
-- For You is deliberately composed of two populations: a head of
|
||||
-- top-scored similarity matches ("taste" picks) and a tail sampled from
|
||||
-- deeper in the candidate ranking ("fresh" picks — the freshness
|
||||
-- injection). Before this the metrics could only judge For You as one
|
||||
-- blob, so a high skip rate couldn't be read as "the taste engine is
|
||||
-- missing" vs "the freshness tax is too high".
|
||||
--
|
||||
-- Two denormalized columns, both nullable:
|
||||
--
|
||||
-- 1. playlist_tracks.pick_kind — stamped by the system-playlist builder
|
||||
-- at snapshot build time. NULL for manual playlists and for system
|
||||
-- variants that don't split (Discover, Songs like X, discovery
|
||||
-- mixes). System snapshots are atomically replaced daily, so the
|
||||
-- column never goes stale within a snapshot.
|
||||
--
|
||||
-- 2. play_events.pick_kind — stamped at play-ingestion time by looking
|
||||
-- the track up in the user's CURRENT For You snapshot. Attribution
|
||||
-- must be frozen at play time: For You rebuilds daily, so a 30-day
|
||||
-- metrics window spans ~30 snapshots and a join-at-read against the
|
||||
-- live snapshot would misattribute nearly everything. Plays that
|
||||
-- predate this feature (or whose track already rotated out, e.g. a
|
||||
-- late offline replay) stay NULL → reported as unattributed.
|
||||
|
||||
ALTER TABLE playlist_tracks
|
||||
ADD COLUMN pick_kind text
|
||||
CONSTRAINT playlist_tracks_pick_kind_check
|
||||
CHECK (pick_kind IN ('taste', 'fresh'));
|
||||
|
||||
ALTER TABLE play_events
|
||||
ADD COLUMN pick_kind text
|
||||
CONSTRAINT play_events_pick_kind_check
|
||||
CHECK (pick_kind IN ('taste', 'fresh'));
|
||||
@@ -1,19 +0,0 @@
|
||||
-- Rows stamped with the widened vocabulary must be cleared before the
|
||||
-- narrow CHECK can be re-added; NULL reads as "unattributed", which is
|
||||
-- the honest downgrade.
|
||||
UPDATE play_events SET pick_kind = NULL
|
||||
WHERE pick_kind NOT IN ('taste', 'fresh');
|
||||
UPDATE playlist_tracks SET pick_kind = NULL
|
||||
WHERE pick_kind NOT IN ('taste', 'fresh');
|
||||
|
||||
ALTER TABLE play_events
|
||||
DROP CONSTRAINT play_events_pick_kind_check;
|
||||
ALTER TABLE play_events
|
||||
ADD CONSTRAINT play_events_pick_kind_check
|
||||
CHECK (pick_kind IN ('taste', 'fresh'));
|
||||
|
||||
ALTER TABLE playlist_tracks
|
||||
DROP CONSTRAINT playlist_tracks_pick_kind_check;
|
||||
ALTER TABLE playlist_tracks
|
||||
ADD CONSTRAINT playlist_tracks_pick_kind_check
|
||||
CHECK (pick_kind IN ('taste', 'fresh'));
|
||||
@@ -1,41 +0,0 @@
|
||||
-- Provenance as standard.
|
||||
--
|
||||
-- 0038 introduced pick_kind as a For You one-off ('taste'/'fresh').
|
||||
-- The mechanism — stamp WHY a track is in the snapshot at build time,
|
||||
-- freeze it onto the play at ingestion, break it down in metrics — is
|
||||
-- now the standard for every system mix, so the CHECK vocabulary
|
||||
-- widens to cover:
|
||||
--
|
||||
-- taste / fresh For You head vs freshness-injection tail
|
||||
-- dormant / cross_user / random
|
||||
-- Discover's three candidate buckets — makes
|
||||
-- the 40/30/30 allocation measurable instead
|
||||
-- of a guess
|
||||
-- tier1 / tier2 / tier3 the tiered-eligibility ladder: tier 1 pins the
|
||||
-- mix's exact desire, each higher tier steps
|
||||
-- back a little. Tier
|
||||
-- provenance is how we measure what the
|
||||
-- step-back trades away.
|
||||
--
|
||||
-- Postgres CHECK whitelists can't be altered in place: DROP + re-ADD
|
||||
-- with the expanded list, in the same migration.
|
||||
|
||||
ALTER TABLE playlist_tracks
|
||||
DROP CONSTRAINT playlist_tracks_pick_kind_check;
|
||||
ALTER TABLE playlist_tracks
|
||||
ADD CONSTRAINT playlist_tracks_pick_kind_check
|
||||
CHECK (pick_kind IN (
|
||||
'taste', 'fresh',
|
||||
'dormant', 'cross_user', 'random',
|
||||
'tier1', 'tier2', 'tier3'
|
||||
));
|
||||
|
||||
ALTER TABLE play_events
|
||||
DROP CONSTRAINT play_events_pick_kind_check;
|
||||
ALTER TABLE play_events
|
||||
ADD CONSTRAINT play_events_pick_kind_check
|
||||
CHECK (pick_kind IN (
|
||||
'taste', 'fresh',
|
||||
'dormant', 'cross_user', 'random',
|
||||
'tier1', 'tier2', 'tier3'
|
||||
));
|
||||
@@ -1,3 +0,0 @@
|
||||
DROP TABLE recommendation_tuning_audit;
|
||||
DROP TABLE taste_tuning;
|
||||
DROP TABLE recommendation_weight_profiles;
|
||||
@@ -1,56 +0,0 @@
|
||||
-- Recommendation tuning lab.
|
||||
--
|
||||
-- The scoring weights move out of YAML (radio profile) and out of the
|
||||
-- systemMixWeights hard-code (daily_mix profile) into DB-backed
|
||||
-- settings with live effect — a lab for FINDING good values, which then
|
||||
-- get baked into shipped defaults; nobody should need this card to get
|
||||
-- good recommendations.
|
||||
--
|
||||
-- Rows are seeded by the recsettings service's boot reconcile (the
|
||||
-- coverart SettingsService pattern), not by this migration, so shipped
|
||||
-- defaults live in exactly one place (Go).
|
||||
|
||||
CREATE TABLE recommendation_weight_profiles (
|
||||
profile text PRIMARY KEY
|
||||
CONSTRAINT recommendation_weight_profiles_profile_check
|
||||
CHECK (profile IN ('radio', 'daily_mix')),
|
||||
base_weight double precision NOT NULL,
|
||||
like_boost double precision NOT NULL,
|
||||
recency_weight double precision NOT NULL,
|
||||
skip_penalty double precision NOT NULL,
|
||||
jitter_magnitude double precision NOT NULL,
|
||||
context_weight double precision NOT NULL,
|
||||
similarity_weight double precision NOT NULL,
|
||||
taste_weight double precision NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Taste-profile build knobs: engagement half-life + the completion→
|
||||
-- engagement curve points (taste.Config's tunable subset).
|
||||
CREATE TABLE taste_tuning (
|
||||
singleton boolean PRIMARY KEY DEFAULT true
|
||||
CONSTRAINT taste_tuning_singleton_check CHECK (singleton),
|
||||
half_life_days double precision NOT NULL,
|
||||
engagement_hard_skip double precision NOT NULL,
|
||||
engagement_neutral double precision NOT NULL,
|
||||
engagement_full double precision NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Every knob turn writes one audit row; the metrics trend view
|
||||
-- annotates these on its timeline so cause→effect is visible
|
||||
-- after a change. changes is a jsonb array of {field, old, new}.
|
||||
CREATE TABLE recommendation_tuning_audit (
|
||||
id bigserial PRIMARY KEY,
|
||||
changed_at timestamptz NOT NULL DEFAULT now(),
|
||||
scope text NOT NULL
|
||||
CONSTRAINT recommendation_tuning_audit_scope_check
|
||||
CHECK (scope IN ('radio', 'daily_mix', 'taste')),
|
||||
action text NOT NULL
|
||||
CONSTRAINT recommendation_tuning_audit_action_check
|
||||
CHECK (action IN ('update', 'reset')),
|
||||
changes jsonb NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX recommendation_tuning_audit_changed_at_idx
|
||||
ON recommendation_tuning_audit (changed_at DESC);
|
||||
@@ -1,27 +0,0 @@
|
||||
-- Reverse 0041_discover_taste_unheard.up.sql.
|
||||
--
|
||||
-- Null out any rows stamped with the new value before shrinking the
|
||||
-- CHECK back to the 0039 vocabulary, or the ADD CONSTRAINT would fail
|
||||
-- on existing 'taste_unheard' rows (mirrors 0039's down).
|
||||
UPDATE play_events SET pick_kind = NULL WHERE pick_kind = 'taste_unheard';
|
||||
UPDATE playlist_tracks SET pick_kind = NULL WHERE pick_kind = 'taste_unheard';
|
||||
|
||||
ALTER TABLE playlist_tracks
|
||||
DROP CONSTRAINT playlist_tracks_pick_kind_check;
|
||||
ALTER TABLE playlist_tracks
|
||||
ADD CONSTRAINT playlist_tracks_pick_kind_check
|
||||
CHECK (pick_kind IN (
|
||||
'taste', 'fresh',
|
||||
'dormant', 'cross_user', 'random',
|
||||
'tier1', 'tier2', 'tier3'
|
||||
));
|
||||
|
||||
ALTER TABLE play_events
|
||||
DROP CONSTRAINT play_events_pick_kind_check;
|
||||
ALTER TABLE play_events
|
||||
ADD CONSTRAINT play_events_pick_kind_check
|
||||
CHECK (pick_kind IN (
|
||||
'taste', 'fresh',
|
||||
'dormant', 'cross_user', 'random',
|
||||
'tier1', 'tier2', 'tier3'
|
||||
));
|
||||
@@ -1,29 +0,0 @@
|
||||
-- Discover taste-targeted novelty bucket.
|
||||
--
|
||||
-- Without it, Discover on a single-user server is effectively dormant +
|
||||
-- crude-random, and the per-user taste profile's tags go unused. This adds a
|
||||
-- fourth Discover candidate bucket that ranks unheard tracks by the
|
||||
-- user's taste-profile tag weights ("novelty that fits your vibe"), so
|
||||
-- its picks need a new pick_kind provenance value.
|
||||
--
|
||||
-- Postgres CHECK whitelists can't be altered in place: DROP + re-ADD with
|
||||
-- the expanded list, in the same migration.
|
||||
ALTER TABLE playlist_tracks
|
||||
DROP CONSTRAINT playlist_tracks_pick_kind_check;
|
||||
ALTER TABLE playlist_tracks
|
||||
ADD CONSTRAINT playlist_tracks_pick_kind_check
|
||||
CHECK (pick_kind IN (
|
||||
'taste', 'fresh',
|
||||
'dormant', 'cross_user', 'random', 'taste_unheard',
|
||||
'tier1', 'tier2', 'tier3'
|
||||
));
|
||||
|
||||
ALTER TABLE play_events
|
||||
DROP CONSTRAINT play_events_pick_kind_check;
|
||||
ALTER TABLE play_events
|
||||
ADD CONSTRAINT play_events_pick_kind_check
|
||||
CHECK (pick_kind IN (
|
||||
'taste', 'fresh',
|
||||
'dormant', 'cross_user', 'random', 'taste_unheard',
|
||||
'tier1', 'tier2', 'tier3'
|
||||
));
|
||||
@@ -1,5 +0,0 @@
|
||||
-- Reverse 0042_track_tags.up.sql.
|
||||
DROP INDEX IF EXISTS tracks_tag_source_idx;
|
||||
ALTER TABLE tracks DROP COLUMN IF EXISTS tag_sources_version;
|
||||
ALTER TABLE tracks DROP COLUMN IF EXISTS tag_source;
|
||||
DROP TABLE IF EXISTS track_tags;
|
||||
@@ -1,26 +0,0 @@
|
||||
-- Track-level folksonomy tags for taste enrichment.
|
||||
--
|
||||
-- A global (not per-user) cache of style/mood tags fetched from
|
||||
-- MusicBrainz (keyless) + Last.fm (when a key is configured), keyed by
|
||||
-- track. Feeds the taste recompute's tag facet alongside raw ID3 genre,
|
||||
-- lifting resolution from coarse "Rock" to "post-punk / shoegaze /
|
||||
-- melancholic". The enricher caps to the top-K tags per track at write
|
||||
-- time so a heavily-tagged track can't dominate the profile. weight is a
|
||||
-- normalized folksonomy strength in [0,1]. Mirrors the coverart
|
||||
-- enricher's versioned source-tracking pattern.
|
||||
CREATE TABLE track_tags (
|
||||
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
||||
tag text NOT NULL,
|
||||
weight double precision NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (track_id, tag)
|
||||
);
|
||||
CREATE INDEX track_tags_track_idx ON track_tags (track_id);
|
||||
|
||||
-- Enrichment bookkeeping (mirror artists.artist_art_source):
|
||||
-- tag_source NULL → not yet processed (eligible)
|
||||
-- tag_source 'lastfm' / 'musicbrainz' / 'mixed' → found, cached
|
||||
-- tag_source 'none' → providers returned nothing
|
||||
-- tag_sources_version → bump to re-process none/stale
|
||||
ALTER TABLE tracks ADD COLUMN tag_source text;
|
||||
ALTER TABLE tracks ADD COLUMN tag_sources_version integer NOT NULL DEFAULT 0;
|
||||
CREATE INDEX tracks_tag_source_idx ON tracks (tag_source, tag_sources_version);
|
||||
@@ -1,3 +0,0 @@
|
||||
-- Reverse 0043_tag_provider_settings.up.sql.
|
||||
DROP TABLE IF EXISTS tag_sources_meta;
|
||||
DROP TABLE IF EXISTS tag_provider_settings;
|
||||
@@ -1,38 +0,0 @@
|
||||
-- Tag-enrichment provider settings.
|
||||
--
|
||||
-- Mirrors the cover-art provider-settings substrate (migration 0018) so
|
||||
-- adding a new tag source later is "register a provider + it auto-upserts
|
||||
-- a row here" — never a schema change. The tag enricher reads the enabled
|
||||
-- set + api keys from tag_provider_settings and stamps the current version
|
||||
-- from tag_sources_meta onto tracks.tag_sources_version (added in 0042).
|
||||
--
|
||||
-- current_version starts at 1 while tracks.tag_sources_version defaults to
|
||||
-- 0 (migration 0042), so every existing track is "stale" relative to
|
||||
-- current and gets enriched on the first pass after this migrates.
|
||||
|
||||
CREATE TABLE tag_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 tag_sources_meta (
|
||||
id boolean PRIMARY KEY DEFAULT true,
|
||||
current_version int NOT NULL DEFAULT 1,
|
||||
last_registered_providers_hash text NOT NULL DEFAULT '',
|
||||
CONSTRAINT tag_sources_meta_singleton CHECK (id = true)
|
||||
);
|
||||
INSERT INTO tag_sources_meta (id, current_version) VALUES (true, 1);
|
||||
|
||||
-- Seed the v1 providers. MusicBrainz is the keyless always-on default;
|
||||
-- Last.fm ships disabled and is opt-in once an admin supplies a key in
|
||||
-- Settings: a feature that needs a third-party account is never on by
|
||||
-- default. The
|
||||
-- SettingsService also upserts these at boot, so the seed is belt-and-
|
||||
-- suspenders / documents the intended defaults.
|
||||
INSERT INTO tag_provider_settings (provider_id, enabled, display_order) VALUES
|
||||
('musicbrainz', true, 0),
|
||||
('lastfm', false, 1);
|
||||
@@ -1,2 +0,0 @@
|
||||
-- Reverse 0044_taste_tuning_enriched_tag_scale.up.sql.
|
||||
ALTER TABLE taste_tuning DROP COLUMN IF EXISTS enriched_tag_scale;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- Expose EnrichedTagScale in the tuning lab. Adds the enriched-tag
|
||||
-- weight knob to the taste_tuning singleton so an admin can dial how much
|
||||
-- folksonomy tags count vs raw ID3 genre. DEFAULT 0.5 backfills the
|
||||
-- existing row and matches taste.DefaultConfig().EnrichedTagScale.
|
||||
ALTER TABLE taste_tuning
|
||||
ADD COLUMN enriched_tag_scale double precision NOT NULL DEFAULT 0.5;
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE taste_tuning DROP COLUMN IF EXISTS era_scale;
|
||||
DROP TABLE IF EXISTS taste_profile_eras;
|
||||
@@ -1,26 +0,0 @@
|
||||
-- 0045_taste_profile_eras.up.sql — era/decade taste facet. A third taste
|
||||
-- facet alongside artists + tags:
|
||||
-- signed weights over decade buckets ("1990s") derived from
|
||||
-- albums.release_date, rebuilt daily by internal/taste next to the
|
||||
-- artist/tag facets. Weight is a signed float — positive = drawn to
|
||||
-- that era, negative = passively avoided; magnitude reflects decayed
|
||||
-- engagement. Consumed by the recommendation scorer's taste match.
|
||||
-- Mirrors taste_profile_tags: CASCADE on user delete, indexed by
|
||||
-- (user_id, weight DESC) so "top eras" reads stay cheap.
|
||||
CREATE TABLE taste_profile_eras (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
era text NOT NULL,
|
||||
weight double precision NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, era)
|
||||
);
|
||||
|
||||
CREATE INDEX taste_profile_eras_user_weight_idx
|
||||
ON taste_profile_eras (user_id, weight DESC);
|
||||
|
||||
-- Era-facet build knob, tunable in the lab (mirrors enriched_tag_scale):
|
||||
-- scales how strongly a decade-play imprints on the profile.
|
||||
-- DEFAULT 0.5 backfills the existing singleton and matches
|
||||
-- taste.DefaultConfig().EraScale; 0 disables the era facet entirely.
|
||||
ALTER TABLE taste_tuning
|
||||
ADD COLUMN era_scale double precision NOT NULL DEFAULT 0.5;
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE recommendation_weight_profiles DROP COLUMN IF EXISTS context_time_weight;
|
||||
@@ -1,12 +0,0 @@
|
||||
-- 0046_context_time_weight.up.sql — time-of-day/weekday context conditioning.
|
||||
-- Adds a per-profile scoring weight for the new
|
||||
-- context-affinity term: how strongly a candidate is boosted when its artist's
|
||||
-- play history concentrates in the current daypart × weekday-type cell (in the
|
||||
-- user's local timezone). Mirrors the other ScoringWeights columns.
|
||||
--
|
||||
-- DEFAULT 1.0 backfills both existing profile rows to a modest on-value; the
|
||||
-- Go ShippedRadioWeights/ShippedDailyMixWeights carry the same 1.0 so fresh
|
||||
-- installs seed identically. Reconcile only seeds MISSING rows (ON CONFLICT DO
|
||||
-- NOTHING), so existing rows rely on this DEFAULT until an admin resets.
|
||||
ALTER TABLE recommendation_weight_profiles
|
||||
ADD COLUMN context_time_weight double precision NOT NULL DEFAULT 1.0;
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE taste_tuning DROP COLUMN IF EXISTS mood_scale;
|
||||
DROP TABLE IF EXISTS taste_profile_moods;
|
||||
@@ -1,25 +0,0 @@
|
||||
-- 0047_taste_profile_moods.up.sql — mood taste facet. A fourth taste facet
|
||||
-- alongside artists + tags + eras: signed weights over canonical mood buckets
|
||||
-- (melancholic / energetic / chill / …) derived from a track's enriched
|
||||
-- folksonomy tags via the internal/mood vocabulary, rebuilt daily. Weight is a
|
||||
-- signed float — positive = drawn to that mood, negative = passively avoided.
|
||||
-- Coverage is partial (grows with tag enrichment), so it's a supplement, not a
|
||||
-- foundation. Mirrors taste_profile_tags: CASCADE on user delete, indexed by
|
||||
-- (user_id, weight DESC).
|
||||
CREATE TABLE taste_profile_moods (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
mood text NOT NULL,
|
||||
weight double precision NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, mood)
|
||||
);
|
||||
|
||||
CREATE INDEX taste_profile_moods_user_weight_idx
|
||||
ON taste_profile_moods (user_id, weight DESC);
|
||||
|
||||
-- Mood-facet build knob, tunable in the lab (mirrors era_scale / enriched_tag_
|
||||
-- scale): scales how strongly a mood-tagged play imprints on the profile.
|
||||
-- DEFAULT 0.5 backfills the existing singleton and matches
|
||||
-- taste.DefaultConfig().MoodScale; 0 disables the mood facet entirely.
|
||||
ALTER TABLE taste_tuning
|
||||
ADD COLUMN mood_scale double precision NOT NULL DEFAULT 0.5;
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE play_events DROP COLUMN IF EXISTS device_class;
|
||||
@@ -1,9 +0,0 @@
|
||||
-- 0048_play_events_device_class.up.sql — device-class context conditioning.
|
||||
-- Records which class of device a play came from (mobile / web / …), sent by
|
||||
-- the client on play-start and normalized server-side. Extends the
|
||||
-- time-of-day/weekday affinity cell (0046) to (daypart × weekday × device) for
|
||||
-- the radio path. Nullable + no CHECK: values are normalized in Go, so a new
|
||||
-- client class needs no migration, and historical rows stay NULL → excluded
|
||||
-- from the device dimension (a graceful cold-start; the facet ramps as new
|
||||
-- plays land).
|
||||
ALTER TABLE play_events ADD COLUMN device_class text;
|
||||
@@ -1,2 +0,0 @@
|
||||
DROP INDEX IF EXISTS suggestion_snoozes_expiry_idx;
|
||||
DROP TABLE IF EXISTS suggestion_snoozes;
|
||||
@@ -1,34 +0,0 @@
|
||||
-- 0049_suggestion_snoozes.up.sql — time-boxed "not right now" on a Discover
|
||||
-- artist suggestion.
|
||||
--
|
||||
-- This is NOT a dislike. Minstrel has no "Not for me" / thumbs-down /
|
||||
-- exclusion control — taste is learned from listening — and a snooze
|
||||
-- deliberately isn't one: it records no verdict on
|
||||
-- the music, expires on its own, and MUST NEVER feed the taste profile. It is
|
||||
-- acquisition triage — "I don't want to request this right now" — so the same
|
||||
-- candidate is free to return once snoozed_until passes. Anything that reads
|
||||
-- this table as negative preference signal is a bug.
|
||||
--
|
||||
-- Per-user, never global: one household member parking a
|
||||
-- suggestion must not remove it from anyone else's deck.
|
||||
--
|
||||
-- candidate_mbid is text with NO foreign key, on purpose. Suggestions come
|
||||
-- from artist_similarity_unmatched and are out-of-library BY DEFINITION, so
|
||||
-- there is no artists row to reference — the MBID is the only stable identity
|
||||
-- available. candidate_name is denormalized for the same reason: the manage /
|
||||
-- un-snooze list has nowhere else to resolve a display name from.
|
||||
|
||||
CREATE TABLE suggestion_snoozes (
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
candidate_mbid text NOT NULL,
|
||||
candidate_name text NOT NULL,
|
||||
snoozed_until timestamptz NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, candidate_mbid)
|
||||
);
|
||||
|
||||
-- Supports the gc sweep's unqualified `WHERE snoozed_until < now()` scan. The
|
||||
-- composite PK already covers every per-user read, so this is the only extra
|
||||
-- index worth its write cost at household-scale row counts (same reasoning as
|
||||
-- lidarr_quarantine in 0011).
|
||||
CREATE INDEX suggestion_snoozes_expiry_idx ON suggestion_snoozes (snoozed_until);
|
||||
@@ -1,3 +0,0 @@
|
||||
DROP INDEX IF EXISTS candidate_artist_tag_state_source_idx;
|
||||
DROP TABLE IF EXISTS candidate_artist_tag_state;
|
||||
DROP TABLE IF EXISTS candidate_artist_tags;
|
||||
@@ -1,53 +0,0 @@
|
||||
-- 0050_candidate_artist_tags.up.sql — folksonomy tags for OUT-OF-LIBRARY
|
||||
-- artists.
|
||||
--
|
||||
-- track_tags (0042) cannot hold these: it is FK'd to tracks(id), and a
|
||||
-- Discover candidate has no local row by definition. So this is a parallel
|
||||
-- cache keyed by the candidate's MusicBrainz MBID — the only stable identity
|
||||
-- available for an artist we don't have.
|
||||
--
|
||||
-- Purpose: rank Discover suggestions by overlap between these tags and the
|
||||
-- user's taste_profile_tags, turning "neighbour of an artist you play" into
|
||||
-- "matches the sound you like".
|
||||
--
|
||||
-- GLOBAL, not per-user: a candidate's tags are a property of the artist, not
|
||||
-- of anyone's taste. The per-user part lives entirely in the ranking.
|
||||
--
|
||||
-- weight is a normalized folksonomy strength in [0,1], same scale as
|
||||
-- track_tags, so the two can be compared without a conversion step.
|
||||
CREATE TABLE candidate_artist_tags (
|
||||
candidate_mbid text NOT NULL,
|
||||
tag text NOT NULL,
|
||||
weight double precision NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (candidate_mbid, tag)
|
||||
);
|
||||
|
||||
-- Enrichment bookkeeping. This is a SEPARATE table rather than columns on the
|
||||
-- tags table, because the "providers had nothing" outcome must be recordable
|
||||
-- for a candidate with zero tag rows — otherwise every empty candidate stays
|
||||
-- eligible forever and the worker re-fetches it on every tick.
|
||||
--
|
||||
-- tracks solved the same problem with columns on `tracks` (0042), but there is
|
||||
-- no per-candidate row anywhere to hang them off: artist_similarity_unmatched
|
||||
-- is keyed (seed_artist_id, candidate_mbid, source) and holds MANY rows per
|
||||
-- candidate.
|
||||
--
|
||||
-- Absence of a row here means "never processed", so unlike tracks.tag_source
|
||||
-- this column can be NOT NULL — there is no null-means-pending state to model.
|
||||
-- 'musicbrainz' | 'lastfm' | 'mixed' → found, cached
|
||||
-- 'none' → providers confirmed nothing
|
||||
-- tag_sources_version → bump to re-process settled 'none'
|
||||
--
|
||||
-- A transient failure writes NO row at all (rather than a row it would then
|
||||
-- have to distinguish), which leaves the candidate eligible for the next pass.
|
||||
CREATE TABLE candidate_artist_tag_state (
|
||||
candidate_mbid text PRIMARY KEY,
|
||||
tag_source text NOT NULL,
|
||||
tag_sources_version integer NOT NULL DEFAULT 0,
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Serves the eligibility scan's "settled 'none' under an older version"
|
||||
-- branch. The PK already covers the per-candidate lookups.
|
||||
CREATE INDEX candidate_artist_tag_state_source_idx
|
||||
ON candidate_artist_tag_state (tag_source, tag_sources_version);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user