Signals from MigrationCommands

The lback.core.management.commands.migration.MigrationCommands class provides a wrapper for Alembic, allowing command-line management of database migrations. This utility emits signals at various stages of its operations, which are highly valuable for CI/CD pipelines, automated testing, logging, and monitoring the state and outcomes of database schema changes.

Signal Name

Description

Arguments (kwargs)

migration_commands_initialized

Emitted immediately after the MigrationCommands instance has been initialized.

sender (MigrationCommands): The instance of the class that sent the signal.

alembic_command_started

Emitted just before an Alembic command is executed via a subprocess.

sender (MigrationCommands): The instance of the class.<br>``command`` (str): The primary Alembic command (e.g., “revision”, “upgrade”, “downgrade”).<br>``args`` (tuple of str): Additional arguments passed to the Alembic command.<br>``full_command`` (list of str): The complete command list prepared for subprocess execution.

alembic_command_completed

Emitted when an Alembic command successfully completes its execution.

sender (MigrationCommands): The instance of the class.<br>``command`` (str): The primary Alembic command that completed.<br>``args`` (tuple of str): Additional arguments passed.<br>``returncode`` (int): The exit code of the Alembic subprocess (expected to be 0 for success).<br>``stdout`` (str): The standard output from the Alembic command.<br>``stderr`` (str): The standard error from the Alembic command.

alembic_command_failed

Emitted when an Alembic command fails to execute or returns a non-zero exit code.

sender (MigrationCommands): The instance of the class.<br>``command`` (str): The primary Alembic command that failed.<br>``args`` (tuple of str): Additional arguments passed.<br>``returncode`` (int or None): The exit code of the Alembic subprocess, if available.<br>``stdout`` (str): The standard output from the Alembic command.<br>``stderr`` (str): The standard error from the Alembic command.<br>``error_type`` (str or None): A string indicating the type of error (e.g., “non_zero_exit_code”, “alembic_not_found”, “exception”).<br>``exception`` (Exception or None): The exception object if an unexpected error occurred.

migration_makemigrations_command

Emitted specifically when the makemigrations command (Alembic revision –autogenerate) is invoked.

sender (MigrationCommands): The instance of the class.<br>``message`` (str): The message provided for the migration (or “auto”).

migration_migrate_command

Emitted specifically when the migrate command (Alembic upgrade) is invoked to apply migrations.

sender (MigrationCommands): The instance of the class.<br>``version`` (str): The target migration version (e.g., “head”, a revision ID).

migration_rollback_command

Emitted specifically when the rollback command (Alembic downgrade) is invoked to revert migrations.

sender (MigrationCommands): The instance of the class.<br>``version`` (str): The target version for the downgrade (e.g., “-1” for one step back, or a revision ID).

migration_history_command

Emitted specifically when the history command (Alembic history) is invoked to display migration history.

sender (MigrationCommands): The instance of the class.