fietsboek.updater package

Updating (data migration) logic for fietsboek.

class fietsboek.updater.UpdateScript(source, name)

Bases: object

Represents an update script.

property alembic_version: str

Returns the alembic revisions of the update.

Returns:

The needed alembic revisions.

downgrade(config, alembic_config)

Runs the downgrade migrations of this update script.

See also upgrade().

Parameters:
  • config (dict) – The app configuration.

  • alembic_config (Config) – The alembic config to use.

property id: str

Returns the ID of the update.

Returns:

The id of the update

property previous: list[str]

Returns all dependencies of the update.

Returns:

The IDs of all dependencies of the update.

upgrade(config, alembic_config)

Runs the upgrade migrations of this update script.

This first runs the pre_alembic task, then the alembic migration, and finally the post_alembic task.

Note that this does not ensure that all previous scripts have also been executed.

Parameters:
  • config (dict) – The app configuration.

  • alembic_config (Config) – The alembic config to use.

class fietsboek.updater.UpdateState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

State of the applied updates.

This represents a “summary” of the output that fietsupdate status produces.

OKAY = 1

Everything is good, the data is up to date.

OUTDATED = 2

The data is outdated, the update process should be run.

TOO_NEW = 3

The data contains revisions that are not known to Fietsboek yet.

UNKNOWN = 4

The data version could not be determined.

class fietsboek.updater.Updater(config_path)

Bases: object

A class that implements the updating logic.

This class is responsible for holding all of the update scripts and running them in the right order.

current_versions()

Reads the current version of the data.

Return type:

list[str]

Returns:

The versions, or an empty list if no versions are found.

downgrade(target)

Run the tasks to downgrade to the given target.

This ensures that all succeeding down-migrations are also run.

Parameters:

target (str) – The target revision.

exists(revision_id)

Checks if the revision with the given ID exists.

Parameters:

revision_id (str) – ID of the revision to check.

Return type:

bool

Returns:

True if the revision exists.

has_applied(revision_id, backward=False)

Checks whether the given revision is applied.

By default, this checks if a given update is applied, i.e. the current version is greater-or-equal to the given revision ID. If backward is True, we instead check if the current version is lower-or-equal to the given revision ID.

Note that this function does not raise an error if the given revision ID cannot be found and instead simply returns False. Use exists() to check whether the revision actually exists.

Parameters:
  • revision_id (str) – The revision to check.

  • backward (bool) – Whether to switch the comparison direction.

Return type:

bool

Returns:

True if the current version at least matches the asked revision ID.

heads()

Returns all “heads”, that are the latest revisions.

Return type:

list[str]

Returns:

The heads.

load()

Load all update scripts into memory.

new_revision(revision_id=None)

Creates a new revision with the current versions as dependencies and the current alembic version.

Parameters:

revision_id (Optional[str]) – The revision ID to use. By default, a random string will be generated.

Return type:

str

Returns:

The filename of the revision file in the updater/ directory.

stamp(versions)

Stampts the given version into the version file.

This does not run any updates, it simply updates the version information.

Parameters:

version – The versions to stamp.

state()

Checks the update state of the instance.

This returns a condensed version of what fietsupdate status outputs.

Return type:

UpdateState

Returns:

The update state of the data.

upgrade(target)

Run the tasks to upgrade to the given target.

This ensures that all previous migrations are also run.

Parameters:

target (str) – The target revision.

property version_file: Path

Returns the path to the version file.

Returns:

The path to the data’s version file.

Submodules