Spaces:
Sleeping
Sleeping
Harshit Ghosh commited on
Commit Β·
04c7cc4
1
Parent(s): 8e35842
Fix 500: add missing avatar columns via startup migration
Browse files226 unmodified lines227228229230231232233234235236226 unmodified lines# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββdef init_db():"""Initialize database tables"""with app.app_context():db.create_all()logger.info("Database initialized")# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ# MODEL & INFERENCE STATE226 unmodified lines227228229230231232233234235236237238239240241242243244245246247248249250251226 unmodified lines# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββdef init_db():"""Initialize database tables and run lightweight column migrations."""with app.app_context():db.create_all()# Safe column additions for existing deployments.# IF NOT EXISTS is supported by PostgreSQL 9.6+ and is a no-op if the column already exists.migrations = ["ALTER TABLE users ADD COLUMN IF NOT EXISTS avatar_url VARCHAR(500)","ALTER TABLE users ADD COLUMN IF NOT EXISTS avatar_public_id VARCHAR(255)",# pending_otps is created by create_all() on first deploy; no ALTER needed.]with db.engine.connect() as conn:for sql in migrations:try:conn.execute(db.text(sql))except Exception as exc:logger.warning("Migration skipped (%s): %s", sql, exc)conn.commit()logger.info("Database initialized and migrations applied")# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ# MODEL & INFERENCE STATE
app_new.py+17-2