feat: Run database migrations in a thread pool to avoid blocking during initialization
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from collections.abc import AsyncGenerator, Callable
|
||||
|
||||
from alembic.config import Config
|
||||
@@ -49,8 +50,10 @@ async def init_db() -> None:
|
||||
# Get the alembic config
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
|
||||
# Run migrations to the latest revision
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
# Run migrations to the latest revision in a thread pool to avoid blocking
|
||||
await asyncio.get_event_loop().run_in_executor(
|
||||
None, command.upgrade, alembic_cfg, "head",
|
||||
)
|
||||
logger.info("Database migrations completed successfully")
|
||||
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user