File size: 843 Bytes
b0b150b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

from core.database import engine, Base
from sqlalchemy import text, inspect

def run_migration():
    print("Running migration: Add preferences to users table...")
    inspector = inspect(engine)
    columns = [col['name'] for col in inspector.get_columns('users')]
    
    if 'preferences' not in columns:
        try:
            with engine.connect() as conn:
                # Add JSON column for preferences
                conn.execute(text("ALTER TABLE users ADD COLUMN preferences JSON DEFAULT '{}'"))
                conn.commit()
            print("✅ Successfully added 'preferences' column to 'users' table.")
        except Exception as e:
            print(f"❌ Error adding column: {e}")
    else:
        print("ℹ️ Column 'preferences' already exists in 'users' table.")

if __name__ == "__main__":
    run_migration()