Skip to content

Commit

Permalink
Disregard migrations older than the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Jablon committed Jul 23, 2020
1 parent 8e8f5c8 commit d863afc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions septentrion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions septentrion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit d863afc

Please sign in to comment.