diff --git a/flight-comparator/database/init_db.py b/flight-comparator/database/init_db.py index d024102..d992820 100644 --- a/flight-comparator/database/init_db.py +++ b/flight-comparator/database/init_db.py @@ -138,6 +138,13 @@ def _migrate_add_routes_unique_index(conn, verbose=True): Collapses any pre-existing duplicate (scan_id, destination) rows first (keeps the row with the lowest id) before creating the index. """ + # Fresh install: routes table doesn't exist yet — schema will create the index + cursor = conn.execute( + "SELECT name FROM sqlite_master WHERE type='table' AND name='routes'" + ) + if not cursor.fetchone(): + return + cursor = conn.execute( "SELECT name FROM sqlite_master WHERE type='index' AND name='uq_routes_scan_dest'" ) @@ -177,6 +184,8 @@ def _migrate_add_scheduled_scan_id_to_scans(conn, verbose=True): """ cursor = conn.execute("PRAGMA table_info(scans)") columns = [row[1] for row in cursor.fetchall()] + if not columns: + return # Fresh install: scans table doesn't exist yet — schema will create the column if 'scheduled_scan_id' in columns: return # Already migrated