36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
from logging.config import fileConfig
|
|
from sqlalchemy import pool
|
|
from sqlalchemy.engine import Connection
|
|
from sqlalchemy.ext.asyncio import async_engine_from_config
|
|
from alembic import context
|
|
import asyncio
|
|
|
|
from app.models.base import Base
|
|
from app.models import player, district
|
|
from app.config import settings
|
|
|
|
config = context.config
|
|
config.set_main_option("sqlalchemy.url", settings.DATABASE_URL)
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
def run_migrations_online():
|
|
connectable = async_engine_from_config(
|
|
config.get_section(config.config_ini_section),
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
|
|
async def do_migrations():
|
|
async with connectable.connect() as connection:
|
|
await connection.run_sync(
|
|
lambda conn: context.configure(
|
|
connection=conn,
|
|
target_metadata=target_metadata,
|
|
)
|
|
)
|
|
await connection.run_sync(context.run_migrations)
|
|
|
|
asyncio.run(do_migrations())
|
|
|
|
run_migrations_online() |