Performance: Alembic migrations
MEDIUM IMPACT
Alembic migrations affect backend database schema changes and can indirectly impact frontend load times if migrations block API responses.
from alembic import command from alembic.config import Config alembic_cfg = Config("alembic.ini") # Run migrations separately before starting the app # or run migrations asynchronously in a background task import asyncio async def run_migrations_async(): loop = asyncio.get_running_loop() await loop.run_in_executor(None, lambda: command.upgrade(alembic_cfg, "head")) # Call run_migrations_async() before serving requests
from alembic import command from alembic.config import Config alembic_cfg = Config("alembic.ini") command.upgrade(alembic_cfg, "head") # runs migrations synchronously on app start
| Pattern | Backend Blocking | API Response Delay | User Impact | Verdict |
|---|---|---|---|---|
| Synchronous migrations during app start | High | High | Delays page load and interaction | [X] Bad |
| Asynchronous or pre-run migrations | None during requests | Minimal | Smooth user experience | [OK] Good |