Skip to content

Commit

Permalink
Initial stab for migrations code... want to see if there more cases f…
Browse files Browse the repository at this point in the history
…irst
  • Loading branch information
yarikoptic committed May 15, 2024
1 parent 7529d69 commit 0f7b5bf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tools/schemacode/bidsschematools/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ def migrate_participants(dataset_path: Path):
lgr.info(f" - migrated content in {new_file}")


def migrate_tsv_columns(dataset_path: Path):
"""
Rename some columns in .tsv (and corresponding sidecar .json)
"""
# TODO: ideally here we would not provide file_glob
# but rather take schema and deduce which files could have
# the column... alternatively - consider all .tsv files and
# their .json files (note -- could be above and multiple given
# inheritance principle)
for col_from, col_to, file_glob in (
# https://github.com/bids-standard/bids-2-devel/issues/78
("hplc_recovery_fractions", "hplc_recovery_fraction", "*_blood.*"),
# https://github.com/bids-standard/bids-2-devel/issues/15
("units", "unit", "_channels.*"), # dependency on migrate_participants
# ??? Any other columns to rename for some reason?
):
raise NotImplementedError()


def migrate_dataset(dataset_path):
lgr.info(f"Migrating dataset at {dataset_path}")
dataset_path = Path(dataset_path)
Expand All @@ -74,6 +93,7 @@ def migrate_dataset(dataset_path):
for migration in [
migrate_participants,
migrate_version,
migrate_tsv_columns, # depends on migrate_participants
]:
lgr.info(f" - applying migration {migration.__name__}")
migration(dataset_path)
Expand Down

0 comments on commit 0f7b5bf

Please sign in to comment.