Add migrate_db() to add missing columns to existing servers table
All checks were successful
Build-Publish / build (linux/amd64) (push) Successful in 5s
Build-Publish / build (linux/arm64) (push) Successful in 13s
Build-Publish / create-manifest (push) Successful in 1s
Build-Publish / publish-template (push) Successful in 8s

This commit is contained in:
j
2026-03-08 13:47:22 +13:00
parent 95c20df073
commit 6add015185

View File

@@ -412,10 +412,30 @@ def usage_color(percent):
# --- Main --- # --- 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__': if __name__ == '__main__':
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True) os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
migrate_db()
logger.info("Database ready at %s", DB_PATH) logger.info("Database ready at %s", DB_PATH)
# Start collector thread # Start collector thread