database fix
This commit is contained in:
+23
-1
@@ -96,7 +96,7 @@ class NFOGuardDatabase:
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# Add has_video_file columns if they don't exist (migration)
|
# Add missing columns if they don't exist (migration)
|
||||||
try:
|
try:
|
||||||
cursor.execute("ALTER TABLE episodes ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE")
|
cursor.execute("ALTER TABLE episodes ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE")
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
@@ -109,6 +109,18 @@ class NFOGuardDatabase:
|
|||||||
# Column already exists
|
# Column already exists
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Check if movies table has path column, add if missing
|
||||||
|
cursor.execute("PRAGMA table_info(movies)")
|
||||||
|
columns = [row[1] for row in cursor.fetchall()]
|
||||||
|
if 'path' not in 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
|
||||||
|
|
||||||
# Create indexes
|
# Create indexes
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_imdb ON episodes(imdb_id)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_imdb ON episodes(imdb_id)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_video ON episodes(has_video_file)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_video ON episodes(has_video_file)")
|
||||||
@@ -140,10 +152,20 @@ class NFOGuardDatabase:
|
|||||||
"""Insert or update movie record"""
|
"""Insert or update movie record"""
|
||||||
with self.get_connection() as conn:
|
with self.get_connection() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
try:
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT OR REPLACE INTO movies (imdb_id, path, last_updated)
|
INSERT OR REPLACE INTO movies (imdb_id, path, last_updated)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
""", (imdb_id, path, datetime.utcnow().isoformat()))
|
""", (imdb_id, path, datetime.utcnow().isoformat()))
|
||||||
|
except sqlite3.OperationalError as e:
|
||||||
|
if "no column named path" in str(e):
|
||||||
|
# Fallback for databases without path column - just insert imdb_id
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT OR REPLACE INTO movies (imdb_id, last_updated)
|
||||||
|
VALUES (?, ?)
|
||||||
|
""", (imdb_id, datetime.utcnow().isoformat()))
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def upsert_movie_dates(self, imdb_id: str, released: Optional[str],
|
def upsert_movie_dates(self, imdb_id: str, released: Optional[str],
|
||||||
dateadded: Optional[str], source: str, has_video_file: bool = False):
|
dateadded: Optional[str], source: str, has_video_file: bool = False):
|
||||||
|
|||||||
Reference in New Issue
Block a user