diff --git a/db.py b/db.py index fc85aa9..a335808 100644 --- a/db.py +++ b/db.py @@ -65,6 +65,19 @@ def init_db() -> None: cached_at TEXT NOT NULL ); """) + _migrate(conn) + + +def _migrate(conn: sqlite3.Connection) -> None: + existing = {row[1] for row in conn.execute("PRAGMA table_info(sync_runs)")} + if "books_imported" not in existing: + conn.execute("ALTER TABLE sync_runs ADD COLUMN books_imported INTEGER DEFAULT 0") + for old_col in ("books_uploaded", "books_skipped"): + if old_col in existing: + try: + conn.execute(f"ALTER TABLE sync_runs DROP COLUMN {old_col}") + except Exception: + pass # --- Settings ---