"""Alembic environment -- generated by alembic_setup.py.""" from __future__ import annotations import asyncio import sys from pathlib import Path from alembic import context sys.path.insert(0, str(Path(__file__).resolve().parents[1])) import alembic_setup as setup # noqa: E402 import db_setup # noqa: E402 metadata = setup.target_metadata() options = setup.context_options() def run(connection) -> None: context.configure(connection=connection, target_metadata=metadata, **options) with context.begin_transaction(): context.run_migrations() if context.is_offline_mode(): context.configure( url=db_setup.database_url(async_driver=False), target_metadata=metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, **options, ) with context.begin_transaction(): context.run_migrations() elif (connection := context.config.attributes.get("connection")) is not None: run(connection) # alembic_setup passed an already-open connection else: asyncio.run(setup.run_standalone(run)) # bare `alembic` CLI