Api
mongorunway.api
¤
A module that provides high-level tools for public use.
__all__: typing.Sequence[str] = ('create_app', 'raise_if_migration_version_mismatch', 'migration', 'migration_with_rule')
module-attribute
¤
create_app(name, configuration=None, *, raise_on_none=False, verbose_exc=False)
¤
Creates a migration application.
Creates a migration application based on the provided parameters. Uses a use case to initialize the application configuration.
PARAMETER | DESCRIPTION |
---|---|
name |
The name of the application for which the creation options will be taken from the configuration file. The application name should match the application name in the configuration file.
TYPE:
|
configuration |
The path to the configuration file or the configuration object required for initializing the application.
TYPE:
|
raise_on_none |
By default, the use-cases return None and do not raise exceptions.
If
TYPE:
|
verbose_exc |
In case of an exception being raised on a failed attempt to initialize
the application, the exception information will be more detailed if
TYPE:
|
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If |
RETURNS | DESCRIPTION |
---|---|
typing.Union[MigrationApp, typing.Optional[MigrationApp]]
|
If |
Source code in mongorunway\api.py
migration(process_func)
¤
Wraps a function in a migration process.
Wraps a function in a migration process. The function should return
either a ready-to-use migration process object or a sequence containing
implementations of migration command interfaces. Otherwise, an exception
will be raised (see the Raises
section).
Note
name: If the provided object does not have the __name__
attribute, the default name UNDEFINED_PROCESS
will be set, which is
used for debugging and logging migration processes.
globals: If the provided object does not have the __globals__
attribute, an AttributeError
will be raised (see the Raises
section).
PARAMETER | DESCRIPTION |
---|---|
process_func |
The function that returns either a ready-to-use migration process object or a sequence containing implementations of migration command interfaces.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
domain_migration.MigrationProcess
|
A migration process object that contains information about the migration version, process name, and set of migration commands. If the function returns an already created migration process, no new objects will be created. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the function did not return an instance of the migration process class and the return value is not an instance of collections.abc.Sequence. |
AttributeError
|
If the function did not return an instance of the migration process
class and the module where the function is implemented does not contain
the global value |
Source code in mongorunway\api.py
migration_with_rule(rule)
¤
Adds a rule to the migration process.
Returns the provided migration process object with the added rule.
PARAMETER | DESCRIPTION |
---|---|
rule |
The rule to add to the migration process. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the value passed to the decorator is not an instance of the migration process class. |
Source code in mongorunway\api.py
raise_if_migration_version_mismatch(application, expected_version)
¤
Raises an error if the versions do not match.
Raises an error if the provided version or version getter does not
match the version of the given migration application. The expected
version or the return value of the expected version getter should
be an instance of the int
class. Otherwise, the comparison operation
may behave unpredictably.
PARAMETER | DESCRIPTION |
---|---|
application |
The migration application whose version you want to check.
TYPE:
|
expected_version |
The expected version of the current migration application.
The expected version or the return value of the expected version
getter should be an instance of the |
RAISES | DESCRIPTION |
---|---|
ValueError
|
Raises an error if the provided version or version getter does not match the version of the given migration application. |