swh.storage.cassandra.migrations module#

class swh.storage.cassandra.migrations.MigrationStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

PENDING = 'pending'#

The migration was not applied yet

RUNNING = 'running'#
COMPLETED = 'completed'#
class swh.storage.cassandra.migrations.Migration(id: str, dependencies: set[str], min_read_version: str, script: Callable[[swh.storage.cassandra.cql.CqlRunner], NoneType] | None, help: str | None, required: bool)[source]#

Bases: object

id: str#

Unique identifier of this migration.

Should have the format: YYYY-MM-DD_developer_readable_name

dependencies: set[str]#

Set of identifiers of migrations this migration depends on

min_read_version: str#

Lowest version of the Python code that should be allowed to read the database if this migration is applied

script: Callable[[CqlRunner], None] | None#

If provided, this is a function that runs the migration.

If not provided, the migration must be run manually, using steps described in the documentation

help: str | None#

Documentation of the migration

Typically describes what to do if script is None.

required: bool#

Whether this migration must be applied for the current version of the Python code to allow instantiating swh.storage.cassandra.CassandraStorage.

swh.storage.cassandra.migrations.list_migrations(cql_runner: CqlRunner, rows: Sequence[MigrationRow] | None = None) list[tuple[Migration, MigrationStatus]][source]#

Returns all known migrations, in topological order

rows, should be the value returned by cql_runner.migration_list.

This includes migrations that are not required to instantiate swh.storage.cassandra.CassandraStorage.

swh.storage.cassandra.migrations.apply_migrations(cql_runner: CqlRunner, ids_to_apply: Iterable[str]) tuple[bool, Sequence[Migration], Sequence[Migration]][source]#

Applies migrations with the given ids (unless they already are).

Returns:

  • whether any was run, and

  • which migrations cannot run because they are missing dependencies

  • which migrations still need to be run manually.

swh.storage.cassandra.migrations.create_migrations_table_if_needed(cql_runner: CqlRunner) None[source]#