import asyncio from alembic import command from alembic.config import Config from app.db import engine async def test_downgrade_to_base_then_upgrade_again(alembic_cfg: Config) -> None: # alembic's env.py runs its own event loop, so keep it off this one. await asyncio.to_thread(command.downgrade, alembic_cfg, "base") await asyncio.to_thread(command.upgrade, alembic_cfg, "head") # The recreated enum type has a new OID that pooled asyncpg connections have not seen; # reconnect so later tests (and the database left at head) are unaffected. await engine.dispose()