github-actions[bot]
Automated Deploy: 0d5b759d8eca219a25b3ab717925e73a66bbf4a4
2756f0f
Raw History Blame Contribute Delete
1.07 kB
"""Alembic environment: uses DATABASE_URL from app settings and the app's metadata."""
import asyncio
from logging.config import fileConfig
from alembic import context
from sqlalchemy.ext.asyncio import create_async_engine
from app.core.config import get_settings
from app.models import Base
if context.config.config_file_name:
fileConfig(context.config.config_file_name)
target_metadata = Base.metadata
def _run(connection) -> None:
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True)
with context.begin_transaction():
context.run_migrations()
async def _run_async() -> None:
engine = create_async_engine(get_settings().database_url)
async with engine.connect() as connection:
await connection.run_sync(_run)
await engine.dispose()
if context.is_offline_mode():
context.configure(url=get_settings().database_url, target_metadata=target_metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
else:
asyncio.run(_run_async())