another DB table

This commit is contained in:
2025-09-14 13:31:54 -04:00
parent b1f670415d
commit 05ba16666e
3 changed files with 66 additions and 32 deletions
+23 -20
View File
@@ -97,29 +97,32 @@ class NFOGuardDatabase:
""")
# Add missing columns if they don't exist (migration)
try:
cursor.execute("ALTER TABLE episodes ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE")
except sqlite3.OperationalError:
# Column already exists
pass
try:
cursor.execute("ALTER TABLE movies ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE")
except sqlite3.OperationalError:
# Column already exists
pass
# Check if movies table has path column, add if missing
# Check current schema and add missing columns
cursor.execute("PRAGMA table_info(movies)")
columns = [row[1] for row in cursor.fetchall()]
if 'path' not in columns:
movie_columns = [row[1] for row in cursor.fetchall()]
cursor.execute("PRAGMA table_info(episodes)")
episode_columns = [row[1] for row in cursor.fetchall()]
# Add missing columns to movies table
if 'path' not in movie_columns:
cursor.execute("ALTER TABLE movies ADD COLUMN path TEXT")
# Update existing records with a placeholder path
cursor.execute("UPDATE movies SET path = '/unknown/path/' || imdb_id WHERE path IS NULL")
# Make path NOT NULL after adding it
# Note: SQLite doesn't support ALTER COLUMN, so we'd need to recreate table
# For now, just ensure new records have paths
if 'has_video_file' not in movie_columns:
cursor.execute("ALTER TABLE movies ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE")
if 'last_updated' not in movie_columns:
cursor.execute("ALTER TABLE movies ADD COLUMN last_updated TEXT")
cursor.execute("UPDATE movies SET last_updated = datetime('now') WHERE last_updated IS NULL")
# Add missing columns to episodes table
if 'has_video_file' not in episode_columns:
cursor.execute("ALTER TABLE episodes ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE")
if 'last_updated' not in episode_columns:
cursor.execute("ALTER TABLE episodes ADD COLUMN last_updated TEXT")
cursor.execute("UPDATE episodes SET last_updated = datetime('now') WHERE last_updated IS NULL")
# Create indexes
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_imdb ON episodes(imdb_id)")