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) <noreply@anthropic.com>
This commit is contained in:
parent
57484619c1
commit
11a8256e6a
1 changed files with 4 additions and 0 deletions
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue