Files
worldquant-alpha-system/backend/migrations/env.py
T

29 lines
787 B
Python
Raw Normal View History

import asyncio
from alembic import context
from sqlalchemy.ext.asyncio import create_async_engine
from app.config import Settings
from app.models import Base
def migrations(connection):
context.configure(connection=connection, target_metadata=Base.metadata, compare_type=True)
with context.begin_transaction():
context.run_migrations()
async def run():
engine = create_async_engine(Settings().database_url)
async with engine.connect() as connection:
await connection.run_sync(migrations)
await engine.dispose()
if context.is_offline_mode():
context.configure(url=Settings().database_url, target_metadata=Base.metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
else:
asyncio.run(run())