Skip to content

Commit

Permalink
Create once-off migration for linking parent records
Browse files Browse the repository at this point in the history
  • Loading branch information
marksparkza committed Aug 14, 2023
1 parent 60bd949 commit f9916a9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bin/onceoff
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python

import argparse
import pathlib
import sys
from importlib import import_module

rootdir = pathlib.Path(__file__).parent.parent
sys.path.append(str(rootdir))

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('module_name')
parser.add_argument('function_name')

args = parser.parse_args()
onceoff_mod = import_module(f'migrate.onceoff.{args.module_name}')
onceoff_func = getattr(onceoff_mod, args.function_name)

onceoff_func()
14 changes: 14 additions & 0 deletions migrate/onceoff/link_parent_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sqlalchemy import select

from odp.api.routers.record import get_parent_id
from odp.db import Session
from odp.db.models import Record


def set_parent_ids():
for record in Session.execute(
select(Record)
).scalars().all():
record.parent_id = get_parent_id(record.metadata_, record.schema_id)

Session.commit()

0 comments on commit f9916a9

Please sign in to comment.