diff --git a/septentrion/core.py b/septentrion/core.py index b87095d..4bcb97f 100644 --- a/septentrion/core.py +++ b/septentrion/core.py @@ -145,6 +145,11 @@ def build_migration_plan(settings: configuration.Settings) -> Iterable[Dict[str, "version {} not found.".format(settings.TARGET_VERSION) ) + if settings.SCHEMA_VERSION: + versions_to_apply = list( + utils.since(versions_to_apply, settings.SCHEMA_VERSION) + ) + # get plan for each version to apply for version in versions_to_apply: version_plan = [] @@ -177,6 +182,14 @@ def describe_migration_plan( with stylist.activate("title") as echo: echo("Current version is {}".format(current_version)) + schema_version = settings.SCHEMA_VERSION + if schema_version: + with stylist.activate("title") as echo: + echo("Schema version is {}".format(schema_version)) + else: + with stylist.activate("title") as echo: + echo("No explicit schema version. All migrations are considered.") + target_version = settings.TARGET_VERSION with stylist.activate("title") as echo: echo("Target version is {}".format(target_version)) diff --git a/septentrion/utils.py b/septentrion/utils.py index 0c23ef1..4139ee1 100644 --- a/septentrion/utils.py +++ b/septentrion/utils.py @@ -2,6 +2,7 @@ All functions in here should be easily unit testable """ +import itertools from typing import Iterable, TypeVar from septentrion import exceptions, versions @@ -37,3 +38,15 @@ def until(iterable: Iterable[T], value: T) -> Iterable[T]: break else: raise ValueError("{} not found".format(value)) + + +def since(iterable: Iterable[T], value: T) -> Iterable[T]: + """ + Returns the values from iterable starting after the element is found + >>> list(until(range(300), 297)) + [298, 299] + """ + it = itertools.dropwhile((lambda x: x != value), iterable) + # Drop the first element + next(it) + yield from it