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:
@@ -67,7 +67,7 @@ func (h *handlers) handleUpdateFingerprintSettings(w http.ResponseWriter, r *htt
|
|||||||
AutoResolve: autoResolve,
|
AutoResolve: autoResolve,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Validation mirrors migration 0061's CHECKs and names the field.
|
// Validation mirrors fingerprint_settings's CHECKs and names the field.
|
||||||
if errors.Is(err, library.ErrFingerprintSettingOutOfRange) {
|
if errors.Is(err, library.ErrFingerprintSettingOutOfRange) {
|
||||||
writeErr(w, apierror.BadRequest("invalid_setting", err.Error()))
|
writeErr(w, apierror.BadRequest("invalid_setting", err.Error()))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// validDiagnosticKinds is the COARSE category whitelist. Mirrors the
|
// validDiagnosticKinds is the COARSE category whitelist. Mirrors the
|
||||||
// CHECK constraint in migration 0036 — keep both in sync (per the
|
// CHECK constraint on diagnostic_events.kind — keep both in sync (per the
|
||||||
// enum-CHECK-whitelist rule). The finer event discriminator + all
|
// enum-CHECK-whitelist rule). The finer event discriminator + all
|
||||||
// event-specific fields live inside each event's payload, so new event
|
// event-specific fields live inside each event's payload, so new event
|
||||||
// variants do NOT require a new category here.
|
// variants do NOT require a new category here.
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ func (h *handlers) handleGetRecommendationMetrics(w http.ResponseWriter, r *http
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pickKindLabels is the display vocabulary for play_events.pick_kind
|
// pickKindLabels is the display vocabulary for play_events.pick_kind
|
||||||
// values (mirrors the CHECK in migration 0041). Every system mix that
|
// values (mirrors the CHECK on play_events.pick_kind). Every system mix that
|
||||||
// stamps provenance gets its breakdown from this one map — adding a
|
// stamps provenance gets its breakdown from this one map — adding a
|
||||||
// stamping mix needs no metrics change.
|
// stamping mix needs no metrics change.
|
||||||
var pickKindLabels = map[string]string{
|
var pickKindLabels = map[string]string{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
// The Subsonic password is for clients that sign in with Subsonic's t/s
|
// The Subsonic password is for clients that sign in with Subsonic's t/s
|
||||||
// scheme (md5 of the password plus a salt). Checking that needs the password
|
// scheme (md5 of the password plus a salt). Checking that needs the password
|
||||||
// itself, so it is stored readable (migration 0003). That is why Minstrel
|
// itself, so it is stored readable (users.subsonic_password). That is why Minstrel
|
||||||
// generates it rather than letting the user choose one: a generated value
|
// generates it rather than letting the user choose one: a generated value
|
||||||
// can never be a login password reused from somewhere else, so a leaked
|
// can never be a login password reused from somewhere else, so a leaked
|
||||||
// users table gives up access to this server's /rest API and nothing more.
|
// users table gives up access to this server's /rest API and nothing more.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Valid `kind` values. Mirrors the CHECK constraint in migration 0032
|
// Valid `kind` values. Mirrors playback_errors_kind_check
|
||||||
// — keep both lists in sync if you add a kind here, otherwise inserts
|
// — keep both lists in sync if you add a kind here, otherwise inserts
|
||||||
// pass the handler whitelist and trip the DB constraint instead.
|
// pass the handler whitelist and trip the DB constraint instead.
|
||||||
var validPlaybackErrorKinds = map[string]struct{}{
|
var validPlaybackErrorKinds = map[string]struct{}{
|
||||||
|
|||||||
@@ -120,8 +120,8 @@ type ListTracksNeedingAcoustIDLookupRow struct {
|
|||||||
DurationMs int32
|
DurationMs int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcoustID recording-id lookup. Migration 0069 says what each
|
// AcoustID recording-id lookup. The CHECK on track_acoustid_lookups.state
|
||||||
// lookup state means.
|
// lists the lookup states.
|
||||||
// The lookup worker's queue: present tracks with no tag MBID and no lookup
|
// The lookup worker's queue: present tracks with no tag MBID and no lookup
|
||||||
// since their file last changed. A looked-up id is included once its row is
|
// since their file last changed. A looked-up id is included once its row is
|
||||||
// gone (the file changed), so the new bytes are checked rather than trusted.
|
// gone (the file changed), so the new bytes are checked rather than trusted.
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ type UpdateFingerprintSettingsParams struct {
|
|||||||
AutoResolve bool
|
AutoResolve bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whole-row write from the admin card; migration 0061's CHECKs are the backstop
|
// Whole-row write from the admin card; fingerprint_settings's CHECKs are the backstop
|
||||||
// behind the service's own validation.
|
// behind the service's own validation.
|
||||||
func (q *Queries) UpdateFingerprintSettings(ctx context.Context, arg UpdateFingerprintSettingsParams) (FingerprintSetting, error) {
|
func (q *Queries) UpdateFingerprintSettings(ctx context.Context, arg UpdateFingerprintSettingsParams) (FingerprintSetting, error) {
|
||||||
row := q.db.QueryRow(ctx, updateFingerprintSettings,
|
row := q.db.QueryRow(ctx, updateFingerprintSettings,
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ type ListMissingTrackPairsRow struct {
|
|||||||
// they are different recordings. The caller folds a pair only when each side has
|
// they are different recordings. The caller folds a pair only when each side has
|
||||||
// exactly one candidate; anything else is ambiguous and left alone.
|
// exactly one candidate; anything else is ambiguous and left alone.
|
||||||
//
|
//
|
||||||
// A slot the duplicate resolver emptied (emptied_at, migration 0095) pairs by
|
// A slot the duplicate resolver emptied (emptied_at) pairs by
|
||||||
// title only with a track added since: the album held no copy of the song as
|
// title only with a track added since: the album held no copy of the song as
|
||||||
// long as it is, so one already there under the title is another song.
|
// long as it is, so one already there under the title is another song.
|
||||||
func (q *Queries) ListMissingTrackPairs(ctx context.Context) ([]ListMissingTrackPairsRow, error) {
|
func (q *Queries) ListMissingTrackPairs(ctx context.Context) ([]ListMissingTrackPairsRow, error) {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ type UpsertNormalizationPrefsRow struct {
|
|||||||
UpdatedAt pgtype.Timestamptz
|
UpdatedAt pgtype.Timestamptz
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whole-row write from either client; the CHECKs in migration 0067 back the
|
// Whole-row write from either client; the CHECKs on user_normalization_prefs back the
|
||||||
// handler's own validation.
|
// handler's own validation.
|
||||||
func (q *Queries) UpsertNormalizationPrefs(ctx context.Context, arg UpsertNormalizationPrefsParams) (UpsertNormalizationPrefsRow, error) {
|
func (q *Queries) UpsertNormalizationPrefs(ctx context.Context, arg UpsertNormalizationPrefsParams) (UpsertNormalizationPrefsRow, error) {
|
||||||
row := q.db.QueryRow(ctx, upsertNormalizationPrefs,
|
row := q.db.QueryRow(ctx, upsertNormalizationPrefs,
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ type UpdateNotificationEmailSettingsParams struct {
|
|||||||
BatchWindowMinutes int32
|
BatchWindowMinutes int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migration 0074's CHECKs are the backstop behind the service's validation.
|
// notification_email_settings's CHECKs are the backstop behind the service's validation.
|
||||||
func (q *Queries) UpdateNotificationEmailSettings(ctx context.Context, arg UpdateNotificationEmailSettingsParams) (NotificationEmailSetting, error) {
|
func (q *Queries) UpdateNotificationEmailSettings(ctx context.Context, arg UpdateNotificationEmailSettingsParams) (NotificationEmailSetting, error) {
|
||||||
row := q.db.QueryRow(ctx, updateNotificationEmailSettings, arg.SummaryHour, arg.BatchWindowMinutes)
|
row := q.db.QueryRow(ctx, updateNotificationEmailSettings, arg.SummaryHour, arg.BatchWindowMinutes)
|
||||||
var i NotificationEmailSetting
|
var i NotificationEmailSetting
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type LinkTracksAsSongRow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Song links: copies of one song on different releases share a
|
// Song links: copies of one song on different releases share a
|
||||||
// song_key (migration 0076).
|
// song_key.
|
||||||
// Links the tracks into one song, joining any songs they already belong to.
|
// Links the tracks into one song, joining any songs they already belong to.
|
||||||
// The song keeps the lowest key among them, so linking the same set again
|
// The song keeps the lowest key among them, so linking the same set again
|
||||||
// changes nothing. Returns that key and how many tracks moved to it.
|
// changes nothing. Returns that key and how many tracks moved to it.
|
||||||
|
|||||||
@@ -1021,7 +1021,7 @@ UPDATE tracks
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Stamps rows the duplicate resolver emptied, whose song the album holds no
|
// Stamps rows the duplicate resolver emptied, whose song the album holds no
|
||||||
// other copy of, with the time they went missing (migration 0095): missing-pair
|
// other copy of, with the time they went missing (emptied_at): missing-pair
|
||||||
// folding then waits for a copy fetched again.
|
// folding then waits for a copy fetched again.
|
||||||
func (q *Queries) MarkTracksEmptied(ctx context.Context, ids []pgtype.UUID) error {
|
func (q *Queries) MarkTracksEmptied(ctx context.Context, ids []pgtype.UUID) error {
|
||||||
_, err := q.db.Exec(ctx, markTracksEmptied, ids)
|
_, err := q.db.Exec(ctx, markTracksEmptied, ids)
|
||||||
|
|||||||
@@ -572,7 +572,7 @@ type SetSubsonicPasswordParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stores (or clears with NULL) the per-user Subsonic legacy credential used
|
// Stores (or clears with NULL) the per-user Subsonic legacy credential used
|
||||||
// for t/s and p auth on /rest/*. Must be plaintext; see migration 0003. Only
|
// for t/s and p auth on /rest/*. Must be plaintext: t/s auth hashes it with a salt. Only
|
||||||
// ever a server-generated value, never the login password.
|
// ever a server-generated value, never the login password.
|
||||||
func (q *Queries) SetSubsonicPassword(ctx context.Context, arg SetSubsonicPasswordParams) error {
|
func (q *Queries) SetSubsonicPassword(ctx context.Context, arg SetSubsonicPasswordParams) error {
|
||||||
_, err := q.db.Exec(ctx, setSubsonicPassword, arg.ID, arg.SubsonicPassword)
|
_, err := q.db.Exec(ctx, setSubsonicPassword, arg.ID, arg.SubsonicPassword)
|
||||||
|
|||||||
@@ -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;
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user