from app import app, db
from sqlalchemy import text

def update_db():
    with app.app_context():
        print("Checking for missing columns...")
        try:
            # Check if profile_picture exists in users table
            db.session.execute(text("SELECT profile_picture FROM users LIMIT 1"))
            print("profile_picture column already exists.")
        except Exception:
            db.session.rollback()
            print("Adding profile_picture column to users table...")
            db.session.execute(text("ALTER TABLE users ADD COLUMN profile_picture VARCHAR(200)"))
            db.session.commit()
            print("Successfully added profile_picture column.")

        # Check for any other missing columns in PIProfile if needed, but the error was specifically 'users.profile_picture'
        
        print("Database schema update complete.")

if __name__ == "__main__":
    update_db()
