From 6add01518500e88d076b8673d1a3092b5406e797 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 8 Mar 2026 13:47:22 +1300 Subject: [PATCH] Add migrate_db() to add missing columns to existing servers table --- app/app.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/app.py b/app/app.py index afb6b29..dda5432 100644 --- a/app/app.py +++ b/app/app.py @@ -412,10 +412,30 @@ def usage_color(percent): # --- Main --- +def migrate_db(): + """Add any missing columns to existing tables.""" + import sqlite3 + conn = sqlite3.connect(DB_PATH) + cursor = conn.cursor() + cursor.execute("PRAGMA table_info(servers)") + existing = {row[1] for row in cursor.fetchall()} + migrations = { + 'url': "ALTER TABLE servers ADD COLUMN url VARCHAR(1024) DEFAULT ''", + 'notes': "ALTER TABLE servers ADD COLUMN notes TEXT DEFAULT ''", + } + for col, sql in migrations.items(): + if col not in existing: + cursor.execute(sql) + logger.info("Added column '%s' to servers table", col) + conn.commit() + conn.close() + + if __name__ == '__main__': os.makedirs(os.path.dirname(DB_PATH), exist_ok=True) with app.app_context(): db.create_all() + migrate_db() logger.info("Database ready at %s", DB_PATH) # Start collector thread