Alembic itself is synchronous, your app's engine is async, and the default template doesn't know your settings or your models. Here is a setup that runs migrations through the same async engine and settings as the app, generates predictable files, and gets tested on every test run.
The engine and the declarative base
Everything starts in one module that the app, Alembic and the tests all import:
# app/db.py from sqlalchemy import MetaData from sqlalchemy.ext.asyncio import AsyncSession , async_sessionmaker , create_async_engine from sqlalchemy.orm import DeclarativeBase from sqlalchemy.pool import NullPool
# Stable constraint names, so Alembic autogenerate produces predictable migrations.…