import sqlite3 import os db_path = 'data/hale.db' if not os.path.exists(db_path): print(f"Database {db_path} not found.") else: conn = sqlite3.connect(db_path) cursor = conn.cursor() # List of new columns to add new_columns = [ ('current_action_label', 'TEXT'), ('current_intensity', 'REAL'), ('state_updated_at', 'TIMESTAMP'), ('schedule_json', 'TEXT') ] for col_name, col_type in new_columns: try: print(f"Attempting to add column: {col_name}") cursor.execute(f"ALTER TABLE users ADD COLUMN {col_name} {col_type}") print(f"Successfully added {col_name}") except sqlite3.OperationalError as e: if "duplicate column name" in str(e).lower(): print(f"Column {col_name} already exists.") else: print(f"Error adding {col_name}: {e}") conn.commit() conn.close() print("Migration complete.")