Spaces:
Runtime error
Runtime error
| import sys | |
| import os | |
| from sqlalchemy import create_engine, text | |
| # Add the current directory to sys.path to make imports work | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| from app.core.config import settings | |
| def fix_user_schema(): | |
| print(f"Connecting to database: {settings.DATABASE_URL}") | |
| engine = create_engine(settings.DATABASE_URL) | |
| with engine.connect() as conn: | |
| try: | |
| # Check if column exists (PostgreSQL specific) | |
| check_query = text(""" | |
| SELECT column_name | |
| FROM information_schema.columns | |
| WHERE table_name='users' AND column_name='name'; | |
| """) | |
| result = conn.execute(check_query).fetchone() | |
| if not result: | |
| print("Column 'name' not found in 'users' table. Adding it...") | |
| conn.execute(text("ALTER TABLE users ADD COLUMN name VARCHAR")) | |
| conn.commit() | |
| print("Successfully added 'name' column to 'users' table.") | |
| else: | |
| print("Column 'name' already exists in 'users' table.") | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| # Fallback for SQLite just in case, though error was psycopg2 | |
| if "sqlite" in settings.DATABASE_URL: | |
| try: | |
| conn.execute(text("ALTER TABLE users ADD COLUMN name VARCHAR")) | |
| conn.commit() | |
| print("Added column (SQLite fallback)") | |
| except Exception as sqle: | |
| print(f"SQLite Error: {sqle}") | |
| if __name__ == "__main__": | |
| fix_user_schema() | |