forked from microbiomedata/nmdc-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from microbiomedata/2043_extraction_target_slot
Make `extraction_target` slot multivalued and implement migrator
- Loading branch information
Showing
13 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import List | ||
from nmdc_schema.migrators.migrator_base import MigratorBase | ||
|
||
|
||
class Migrator(MigratorBase): | ||
""" | ||
Migrates data from X to PR192, makes the existing extraction_target slot multivalued and change its name to extraction_targets | ||
Should be run after migrator_from_X_to_PR2_and_PR24.py. | ||
""" | ||
|
||
def upgrade(self): | ||
r"""Migrates the database from conforming to the original schema, to conforming to the new schema.""" | ||
|
||
self.adapter.process_each_document("extraction_set", [self.rename_extraction_target]) | ||
|
||
def rename_extraction_target(self, extraction: dict) -> dict: | ||
r""" | ||
Renames the `extraction_target` field to `extraction_targets` and makes it multivalued. | ||
>>> m = Migrator() | ||
>>> m.rename_extraction_target({'id': 123}) # no `extraction_target` field | ||
{'id': 123} | ||
>>> m.rename_extraction_target({'id': 123, 'extraction_target': 'DNA'}) # test: renames field and casts it as a list value | ||
{'id': 123, 'extraction_targets': ['DNA']} | ||
""" | ||
|
||
self.logger.info(f"Starting migration of {extraction['id']}") | ||
if "extraction_target" in extraction: | ||
extraction["extraction_targets"] = [extraction.pop("extraction_target")] | ||
return extraction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters