Skip to content

Commit

Permalink
Add migration for 0.15.3 data model update (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblurye committed Jan 23, 2020
1 parent e98ea3a commit 3c5043b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cidc_schemas/__init__.py
Expand Up @@ -4,4 +4,4 @@

__author__ = """James Lindsay"""
__email__ = "jlindsay@jimmy.harvard.edu"
__version__ = "0.15.3"
__version__ = "0.15.4"
23 changes: 23 additions & 0 deletions cidc_schemas/migrations.py
Expand Up @@ -40,6 +40,29 @@ def downgrade(metadata: dict, *args, **kwargs) -> MigrationResult:
raise NotImplementedError


class v0_15_2_to_v0_15_3(migration):
"""
v0.15.2: allowed_cohort_names included "Not reported" as an allowed value.
v0.15.3: allowed_cohort_names was updated to use "Not_reported" instead of "Not reported" for this value.
"""

@classmethod
def upgrade(cls, metadata: dict, *args, **kwargs) -> MigrationResult:
for p in metadata.get("participants", []):
if p["cohort_name"] == "Not reported":
p["cohort_name"] = "Not_reported"

return MigrationResult(metadata, {})

@classmethod
def downgrade(cls, metadata: dict, *args, **kwargs):
for p in metadata.get("participants", []):
if p["cohort_name"] == "Not_reported":
p["cohort_name"] == "Not reported"

return MigrationResult(metadata, {})


class v0_10_2_to_v0_11_0(migration):
"""
v0.11.0 allowed_cohort_names and allowed_collection_event_names were
Expand Down
15 changes: 15 additions & 0 deletions tests/test_migrations.py
Expand Up @@ -5,6 +5,7 @@
v0_10_0_to_v0_10_2,
MigrationError,
v0_10_2_to_v0_11_0,
v0_15_2_to_v0_15_3,
)


Expand All @@ -22,6 +23,20 @@ def test_follow_path():
assert _follow_path(d, 1) is None


def test_v0_15_2_to_v0_15_3():
assert v0_15_2_to_v0_15_3.downgrade(
v0_15_2_to_v0_15_3.upgrade({"foo": "bar"}).result
).result == {"foo": "bar"}

ct = {"participants": [{"cohort_name": "Not reported"}, {"cohort_name": "foo"}]}

upgraded_ct = v0_15_2_to_v0_15_3.upgrade(ct).result
assert upgraded_ct["participants"][0]["cohort_name"] == "Not_reported"
assert upgraded_ct["participants"][1]["cohort_name"] == "foo"

assert ct == v0_15_2_to_v0_15_3.downgrade(upgraded_ct).result


def test_v0_10_2_to_v0_11_0():

empty_ct = {}
Expand Down

0 comments on commit 3c5043b

Please sign in to comment.