prefect.server.database.alembic_commands

Functions

with_alembic_lock

with_alembic_lock(fn: Callable[P, R]) -> Callable[P, R]

Decorator that prevents alembic commands from running concurrently. This is necessary because alembic uses a global configuration object that is not thread-safe.

This issue occurred in https://github.com/PrefectHQ/prefect-dask/pull/50, where dask threads were simultaneously performing alembic upgrades, and causing cryptic KeyError: 'config' when del globals_[attr_name].

alembic_config

alembic_config() -> 'Config'

alembic_upgrade

alembic_upgrade(revision: str = 'head', dry_run: bool = False) -> None

Run alembic upgrades on Prefect REST API database

Args:

  • revision: The revision passed to alembic downgrade. Defaults to ‘head’, upgrading all revisions.
  • dry_run: Show what migrations would be made without applying them. Will emit sql statements to stdout.

alembic_downgrade

alembic_downgrade(revision: str = '-1', dry_run: bool = False) -> None

Run alembic downgrades on Prefect REST API database

Args:

  • revision: The revision passed to alembic downgrade. Defaults to ‘base’, downgrading all revisions.
  • dry_run: Show what migrations would be made without applying them. Will emit sql statements to stdout.

alembic_revision

alembic_revision(message: Optional[str] = None, autogenerate: bool = False, **kwargs: Any) -> None

Create a new revision file for the database.

Args:

  • message: string message to apply to the revision.
  • autogenerate: whether or not to autogenerate the script from the database.

alembic_stamp

alembic_stamp(revision: Union[str, list[str], tuple[str, ...]]) -> None

Stamp the revision table with the given revision; don’t run any migrations

Args:

  • revision: The revision passed to alembic stamp.