qfa.cli.migrate#

Run alembic upgrade head under a Postgres advisory lock.

Invoked from entrypoint.sh before uvicorn binds the port, and from make migrate in dev. Multi-replica safe: the session-scoped advisory lock serialises concurrent migrators so non-winners wait for the winner to finish before proceeding.

Run from the project root: Alembic resolves ./alembic.ini from the current working directory.

Module attributes

LOCK_KEY

Stable 64-bit integer key for the migration advisory lock.

Functions

main()

CLI entry point.

run_migrations(db)

Run alembic upgrade head under an advisory lock.

qfa.cli.migrate.LOCK_KEY: int = 7424901234567890#

Stable 64-bit integer key for the migration advisory lock.

async qfa.cli.migrate.run_migrations(db: DatabaseSettings | str) None[source]#

Run alembic upgrade head under an advisory lock.

The lock is session-scoped: it is released automatically when the holding connection closes, so a crashed migrator cannot leave the keyspace permanently held.

Parameters:

db (DatabaseSettings | str) – Either full DB settings (preferred, supports Entra token auth) or an explicit SQLAlchemy URL (used by integration tests).

qfa.cli.migrate.main() int[source]#

CLI entry point.

Returns 0 on success (including the no-op case when usage tracking is disabled).