34 lines
886 B
Python
34 lines
886 B
Python
|
|
import asyncio
|
||
|
|
from logging.config import fileConfig
|
||
|
|
|
||
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
||
|
|
|
||
|
|
from alembic import context
|
||
|
|
|
||
|
|
alembic_cfg = context.config
|
||
|
|
|
||
|
|
if alembic_cfg.config_file_name is not None:
|
||
|
|
fileConfig(alembic_cfg.config_file_name)
|
||
|
|
|
||
|
|
from corvid import config as app_config
|
||
|
|
from corvid.models import Base # noqa: E402 — registers models
|
||
|
|
|
||
|
|
target_metadata = Base.metadata
|
||
|
|
|
||
|
|
|
||
|
|
def do_run_migrations(connection):
|
||
|
|
context.configure(connection=connection, target_metadata=target_metadata)
|
||
|
|
with context.begin_transaction():
|
||
|
|
context.run_migrations()
|
||
|
|
|
||
|
|
|
||
|
|
async def run_async_migrations():
|
||
|
|
engine = create_async_engine(app_config.DATABASE_URL)
|
||
|
|
async with engine.begin() as conn:
|
||
|
|
await conn.run_sync(do_run_migrations)
|
||
|
|
await engine.dispose()
|
||
|
|
|
||
|
|
|
||
|
|
run_migrations_online = lambda: asyncio.run(run_async_migrations())
|
||
|
|
run_migrations_online()
|