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.