import logging import os from alembic.config import Config from alembic import command from flask import Blueprint from app.config import Config as AppConfig migrations_bp = Blueprint("migrations", __name__) def run_migrations(app): """Run database migrations""" try: # Create Alembic configuration object alembic_cfg = Config("alembic.ini") # Get the database URL from your app's config database_url = AppConfig.SQLALCHEMY_DATABASE_URI print(database_url) # Set the SQLAlchemy URL alembic_cfg.set_main_option("sqlalchemy.url", database_url) logging.debug(f"Database URL set to: {database_url}") # Run the migration command.upgrade(alembic_cfg, "head") logging.info("Database migration completed successfully") return True except Exception as e: logging.error(f"Migration failed: {str(e)}") return False