diff --git a/alembic/env.py b/alembic/env.py index 42e258b..8de3258 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -20,6 +20,9 @@ target_metadata = Base.metadata def do_run_migrations(connection: Connection) -> None: + # Alembic's version_table lives inside SCHEMA_NAME, so the schema must + # exist before context.configure() tries to create alembic_version. + connection.exec_driver_sql(f'CREATE SCHEMA IF NOT EXISTS "{SCHEMA_NAME}"') context.configure( connection=connection, target_metadata=target_metadata, @@ -35,6 +38,7 @@ async def run_migrations_online() -> None: connectable = async_engine_from_config(configuration, prefix="sqlalchemy.") async with connectable.connect() as connection: await connection.run_sync(do_run_migrations) + await connection.commit() await connectable.dispose()