-
-
Notifications
You must be signed in to change notification settings - Fork 321
Closed
Description
Bug Description:
Running command.upgrade(alembic_cfg, "head") never returns and blocks the process indefinitely.
Expected Behavior:
The process should complete and return, either successfully or with a failure.
To Reproduce:
def run_migrations():
try:
logger.info("Starting database migrations")
alembic_cfg = Config("alembic.ini")
command.upgrade(alembic_cfg, "head")
logger.info("Database migrations completed successfully")
except Exception as e:
logger.error(f"Migration failed: {e}")
raiseError:
# Copy error here. Please include the full stack trace.
Environment:
- OS: macOS 14.15
- Python: 3.12
- Alembic: 1.13.1
- SQLAlchemy: 2.0.30
- Database: SQLite
- DBAPI: SQLModel 2.0.0
Additional Context:
The following workaround using subprocess works:
def run_migrations():
try:
logger.info("Starting database migrations")
# Run the Alembic upgrade command using subprocess
result = subprocess.run(["alembic", "upgrade", "head"], capture_output=True, text=True)
if result.returncode != 0:
logger.error(f"Alembic upgrade failed: {result.stderr}")
raise RuntimeError(f"Alembic upgrade failed: {result.stderr}")
logger.info("Database migrations completed successfully")
except Exception as e:
logger.error(f"Migration failed: {e}")
raise
finally:
# Ensure the engine is disposed
engine.dispose()
logger.info("Disposed of the engine to close all connections.")Have a nice day!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels