From 78874313cc533d453ece708c165c93c6a7225a83 Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Mon, 22 Jun 2026 23:34:51 -0700 Subject: [PATCH] fix(video): move idx_movies_collection to _POST_INDEXES (broke DB init) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new index on movies.tmdb_collection_id was in video_schema.sql, which executescript runs BEFORE _ensure_columns adds the column on existing DBs — so 'CREATE INDEX ... ON movies(tmdb_collection_id)' failed with 'no such column' and the whole video DB init aborted (500s on every /api/video/* call). Moved the index to _POST_INDEXES (runs after the ALTERs), matching the pattern the code comments already prescribe. The CREATE TABLE columns stay (fresh DBs) + the ALTER migration stays (existing DBs); only the index moved. --- database/video_database.py | 3 +++ database/video_schema.sql | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/database/video_database.py b/database/video_database.py index 65f9f99d..de19ceba 100644 --- a/database/video_database.py +++ b/database/video_database.py @@ -302,6 +302,9 @@ class VideoDatabase: "ON video_wishlist(source_id) WHERE kind = 'video'", "CREATE INDEX IF NOT EXISTS idx_video_wishlist_channel " "ON video_wishlist(parent_source_id) WHERE kind = 'video'", + # Index on movies.tmdb_collection_id — a migration-added column, so it must be + # created AFTER _ensure_columns (the schema executescript runs before the ALTERs). + "CREATE INDEX IF NOT EXISTS idx_movies_collection ON movies(tmdb_collection_id)", ) @classmethod diff --git a/database/video_schema.sql b/database/video_schema.sql index ef6c9c03..d09a8a83 100644 --- a/database/video_schema.sql +++ b/database/video_schema.sql @@ -98,8 +98,9 @@ CREATE TABLE IF NOT EXISTS movies ( updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_movies_tmdb ON movies(tmdb_id); -CREATE INDEX IF NOT EXISTS idx_movies_collection ON movies(tmdb_collection_id); CREATE INDEX IF NOT EXISTS idx_movies_monitored ON movies(monitored, has_file); +-- NOTE: idx on tmdb_collection_id (a migration-added column) lives in _POST_INDEXES, +-- not here — this schema runs BEFORE the ALTER that adds the column on upgraded DBs. CREATE INDEX IF NOT EXISTS idx_movies_release ON movies(release_date); -- Upsert/stale-removal key: the server's native id. Multiple NULLs are allowed -- (wishlist items not yet on a server), so this never blocks non-server rows.