Spaces:
Paused
Paused
File size: 1,428 Bytes
9e497a6 e767948 9e497a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import os
from dotenv import load_dotenv
from database import get_db_connection
load_dotenv()
def migrate():
conn = get_db_connection()
print("Starting migration...")
# List of alter table commands to ensure columns exist
# SQLite/LibSQL doesn't have "IF NOT EXISTS" for ADD COLUMN, so we try/except
alter_queries = [
("users", "role", "TEXT DEFAULT 'user'"),
("users", "is_active", "INTEGER DEFAULT 1"),
("users", "passkey_verified", "INTEGER DEFAULT 0"),
("tasks", "interval_hours", "INTEGER DEFAULT 0"),
("tasks", "scheduled_time", "TEXT DEFAULT ''"), # In case it was missing
("tasks", "speed_mode", "TEXT DEFAULT 'balanced'"),
("tasks", "sweep_status", "TEXT DEFAULT 'idle'"),
("tasks", "deleted_groups", "TEXT DEFAULT '[]'"),
]
for table, column, definition in alter_queries:
try:
print(f"Adding column {column} to {table}...")
conn.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
print(f"Success: Added {column} to {table}")
except Exception as e:
# Most likely column already exists
print(f"Skipped: {column} in {table} (Error: {str(e)})")
if hasattr(conn, "commit"): conn.commit()
if hasattr(conn, "close"): conn.close()
print("Migration finished.")
if __name__ == "__main__":
migrate()
|