Warning

This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

galaxy.model.migrations package

class galaxy.model.migrations.DatabaseConfig(url, template, encoding)[source]

Bases: tuple

url: str

Alias for field number 0

template: str

Alias for field number 1

encoding: str

Alias for field number 2

exception galaxy.model.migrations.InvalidModelIdError(model: str)[source]

Bases: Exception

__init__(model: str) None[source]
class galaxy.model.migrations.AlembicManager(engine: Engine, config_dict: dict | None = None)[source]

Bases: BaseAlembicManager

stamp_model_head(model: ModelId) None[source]

Partial proxy to alembic’s stamp command.

upgrade(model: ModelId) None[source]

Partial proxy to alembic’s upgrade command.

is_up_to_date(model: ModelId) bool[source]

True if the head revision for model in the script directory is stored in the database.

is_under_version_control(model: ModelId) bool[source]

True if the database version table contains a revision that corresponds to a revision in the script directory that has branch label model.

get_model_db_head(model: ModelId) str | None[source]
get_model_script_head(model: ModelId) str | None[source]
galaxy.model.migrations.verify_databases_via_script(gxy_config: DatabaseConfig, tsi_config: DatabaseConfig, is_auto_migrate: bool = False) None[source]
galaxy.model.migrations.verify_databases(gxy_engine: Engine, gxy_template: str | None, gxy_encoding: str | None, tsi_engine: Engine | None, tsi_template: str | None, tsi_encoding: str | None, is_auto_migrate: bool) None[source]
class galaxy.model.migrations.DatabaseStateVerifier(engine: Engine, model: ModelId, database_template: str | None, database_encoding: str | None, is_auto_migrate: bool, is_new_database: bool | None = False)[source]

Bases: object

__init__(engine: Engine, model: ModelId, database_template: str | None, database_encoding: str | None, is_auto_migrate: bool, is_new_database: bool | None = False) None[source]
property is_auto_migrate: bool
property db_state: DatabaseStateCache
property alembic_manager: AlembicManager
run() None[source]
galaxy.model.migrations.get_last_sqlalchemymigrate_version(model: ModelId) int[source]
galaxy.model.migrations.get_alembic_manager(engine: Engine) AlembicManager[source]
galaxy.model.migrations.get_metadata(model: ModelId) MetaData[source]
galaxy.model.migrations.get_gxy_metadata() MetaData[source]
galaxy.model.migrations.get_tsi_metadata() MetaData[source]

Submodules

galaxy.model.migrations.scripts module

galaxy.model.migrations.scripts.verify_database_is_initialized(db_url: str) None[source]

Intended for use by scripts that run database migrations (manage_db.sh, run_alembic.sh). Those scripts are meant to run on a database that has been initialized with the appropriate metadata (e.g. galaxy or install model).

This function will raise an error if the database does not exist or has not been initialized*.

NOTE: this function cannot determine whether a database has been properly initialized; it can only tell when a database has *not been initialized.

galaxy.model.migrations.scripts.get_configuration(argv: List[str], cwd: str) Tuple[DatabaseConfig, DatabaseConfig, bool][source]

Return a 3-item-tuple with configuration values used for managing databases.

galaxy.model.migrations.scripts.get_configuration_from_file(cwd: str, config_file: str | None = None) Tuple[DatabaseConfig, DatabaseConfig, bool][source]
galaxy.model.migrations.scripts.add_db_urls_to_command_arguments(argv: List[str], gxy_url: str, tsi_url: str) None[source]
galaxy.model.migrations.scripts.invoke_alembic() None[source]

Invoke the Alembic command line runner.

Accept ‘heads’ as the target revision argument to enable upgrading both gxy and tsi in one command. This is consistent with Alembic’s CLI, which allows upgrade heads. However, this would not work for separate gxy and tsi databases: we can’t attach a database url to a revision after Alembic has been invoked with the ‘upgrade’ command and the ‘heads’ argument. So, instead we invoke Alembic for each head.

class galaxy.model.migrations.scripts.LegacyManageDb[source]

Bases: object

LEGACY_CONFIG_FILE_ARG_NAMES = ['-c', '--config', '--config-file']
__init__()[source]
get_gxy_version()[source]

Get the head revision for the gxy branch from the Alembic script directory. (previously referred to as “max/repository version”)

get_gxy_db_version(gxy_db_url=None)[source]

Get the head revision for the gxy branch from the galaxy database. If there is no alembic_version table, get the sqlalchemy migrate version. Raise error if that version is not the latest. (previously referred to as “database version”)

run_upgrade(gxy_db_url=None, tsi_db_url=None)[source]

Alembic will upgrade both branches, gxy and tsi, to their head revisions.

rename_config_argument(argv: List[str]) None[source]

Rename the optional config argument: we can’t use ‘-c’ because that option is used by Alembic.

galaxy.model.migrations.scripts.get_alembic_cfg()[source]
galaxy.model.migrations.scripts.get_alembic_manager(engine: Engine) AlembicManager[source]

galaxy.model.migrations.util module

class galaxy.model.migrations.util.DDLOperation[source]

Bases: ABC

Base class for all DDL operations.

run() Any | None[source]
abstract execute() Any | None[source]
abstract pre_execute_check() bool[source]
abstract log_check_not_passed() None[source]
class galaxy.model.migrations.util.DDLAlterOperation(table_name: str)[source]

Bases: DDLOperation

Base class for DDL operations that implement special handling of ALTER statements. Ref: - https://alembic.sqlalchemy.org/en/latest/ops.html#alembic.operations.Operations.batch_alter_table - https://alembic.sqlalchemy.org/en/latest/batch.html

__init__(table_name: str) None[source]
run() Any | None[source]
execute() Any | None[source]
abstract batch_execute(batch_op) Any | None[source]
abstract non_batch_execute() Any | None[source]
class galaxy.model.migrations.util.CreateTable(table_name: str, *columns: SchemaItem)[source]

Bases: DDLOperation

Wraps alembic’s create_table directive.

__init__(table_name: str, *columns: SchemaItem) None[source]
execute() Table | None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.DropTable(table_name: str)[source]

Bases: DDLOperation

Wraps alembic’s drop_table directive.

__init__(table_name: str) None[source]
execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.CreateIndex(index_name: str, table_name: str, columns: Sequence, **kw: Any)[source]

Bases: DDLOperation

Wraps alembic’s create_index directive.

__init__(index_name: str, table_name: str, columns: Sequence, **kw: Any) None[source]
execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.DropIndex(index_name: str, table_name: str)[source]

Bases: DDLOperation

Wraps alembic’s drop_index directive.

__init__(index_name: str, table_name: str) None[source]
execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.AddColumn(table_name: str, column: Column)[source]

Bases: DDLOperation

Wraps alembic’s add_column directive.

__init__(table_name: str, column: Column) None[source]
execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.DropColumn(table_name: str, column_name: str)[source]

Bases: DDLAlterOperation

Wraps alembic’s drop_column directive.

__init__(table_name: str, column_name: str) None[source]
batch_execute(batch_op) None[source]
non_batch_execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.AlterColumn(table_name: str, column_name: str, **kw: Any)[source]

Bases: DDLAlterOperation

Wraps alembic’s alter_column directive.

__init__(table_name: str, column_name: str, **kw: Any) None[source]
batch_execute(batch_op) None[source]
non_batch_execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.CreateForeignKey(foreign_key_name: str, table_name: str, referent_table: str, local_cols: List[str], remote_cols: List[str], **kw: Any)[source]

Bases: DDLAlterOperation

Wraps alembic’s create_foreign_key directive.

__init__(foreign_key_name: str, table_name: str, referent_table: str, local_cols: List[str], remote_cols: List[str], **kw: Any) None[source]
batch_execute(batch_op) None[source]
non_batch_execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.CreateUniqueConstraint(constraint_name: str, table_name: str, columns: List[str])[source]

Bases: DDLAlterOperation

Wraps alembic’s create_unique_constraint directive.

__init__(constraint_name: str, table_name: str, columns: List[str]) None[source]
batch_execute(batch_op) None[source]
non_batch_execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
class galaxy.model.migrations.util.DropConstraint(constraint_name: str, table_name: str)[source]

Bases: DDLAlterOperation

Wraps alembic’s drop_constraint directive.

__init__(constraint_name: str, table_name: str) None[source]
batch_execute(batch_op) None[source]
non_batch_execute() None[source]
pre_execute_check() bool[source]
log_check_not_passed() None[source]
galaxy.model.migrations.util.create_table(table_name: str, *columns: SchemaItem) Table | None[source]
galaxy.model.migrations.util.drop_table(table_name: str) None[source]
galaxy.model.migrations.util.add_column(table_name: str, column: Column) None[source]
galaxy.model.migrations.util.drop_column(table_name, column_name) None[source]
galaxy.model.migrations.util.alter_column(table_name: str, column_name: str, **kw) None[source]
galaxy.model.migrations.util.create_index(index_name, table_name, columns, **kw) None[source]
galaxy.model.migrations.util.drop_index(index_name, table_name) None[source]
galaxy.model.migrations.util.create_foreign_key(foreign_key_name: str, table_name: str, referent_table: str, local_cols: List[str], remote_cols: List[str], **kw: Any) None[source]
galaxy.model.migrations.util.create_unique_constraint(constraint_name: str, table_name: str, columns: List[str]) None[source]
galaxy.model.migrations.util.drop_constraint(constraint_name: str, table_name: str) None[source]
galaxy.model.migrations.util.table_exists(table_name: str, default: bool) bool[source]

Check if table exists. If running in offline mode, return default.

galaxy.model.migrations.util.column_exists(table_name: str, column_name: str, default: bool) bool[source]

Check if column exists. If running in offline mode, return default.

galaxy.model.migrations.util.index_exists(index_name: str, table_name: str, default: bool) bool[source]

Check if index exists. If running in offline mode, return default.

galaxy.model.migrations.util.foreign_key_exists(constraint_name: str, table_name: str, default: bool) bool[source]

Check if unique constraint exists. If running in offline mode, return default.

galaxy.model.migrations.util.unique_constraint_exists(constraint_name: str, table_name: str, default: bool) bool[source]

Check if unique constraint exists. If running in offline mode, return default.

galaxy.model.migrations.util.legacy_alter_table()[source]

Wrapper required for add/drop column statements. Prevents error when column belongs to a table referenced in a view. Relevant to sqlite only. Ref: https://github.com/sqlalchemy/alembic/issues/1207 Ref: https://sqlite.org/pragma.html#pragma_legacy_alter_table

galaxy.model.migrations.util.transaction()[source]

Wraps multiple statements in upgrade/downgrade revision script functions in a database transaction, ensuring transactional control.

Used for SQLite only. Although SQLite supports transactional DDL, pysqlite does not. Ref: https://bugs.python.org/issue10740