Skip to content

Commit

Permalink
Allow people to initialize a database without
Browse files Browse the repository at this point in the history
Issue: #54
  • Loading branch information
samuelhamard committed Feb 21, 2020
1 parent 224138d commit 7c44388
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions septentrion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def get_closest_version(

# TODO: refactor this and the function below
# TODO: also remove files.get_special_files, it's not really useful
def get_best_schema_version(settings: configuration.Settings) -> versions.Version:
def get_best_schema_version(
settings: configuration.Settings,
) -> Optional[versions.Version]:
"""
Get the best candidate to init the DB.
"""
Expand All @@ -88,8 +90,6 @@ def get_best_schema_version(settings: configuration.Settings) -> versions.Versio
existing_files=schema_files,
)

if version is None:
raise exceptions.SeptentrionException("Cannot find a schema to init the DB.")
return version


Expand Down
3 changes: 2 additions & 1 deletion septentrion/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def migrate(
logger.info("Migration table is empty, loading a schema")
# schema not inited
schema_version = core.get_best_schema_version(settings=settings)
init_schema(settings=settings, init_version=schema_version, stylist=stylist)
if schema_version is not None:
init_schema(settings=settings, init_version=schema_version, stylist=stylist)

# play migrations
with stylist.activate("title") as echo:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def test_get_best_schema_version_ko(mocker, known_versions):
{"target_version": versions.Version.from_string("1.2")}
)

with pytest.raises(exceptions.SeptentrionException):
core.get_best_schema_version(settings=settings)
assert core.get_best_schema_version(settings=settings) is None


def test_build_migration_plan_unknown_version(known_versions):
Expand Down

0 comments on commit 7c44388

Please sign in to comment.