From 11a8256e6acbf5d942173501ddce853ea2e26695 Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Sat, 18 Apr 2026 22:23:30 +0000 Subject: [PATCH] alembic: create schema before initializing version table The payslip_ingest schema must exist before Alembic creates its alembic_version tracking table inside it. Add CREATE SCHEMA IF NOT EXISTS at the top of do_run_migrations. Co-Authored-By: Claude Opus 4.7 (1M context) --- alembic/env.py | 4 ++++ 1 file changed, 4 insertions(+) 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()