-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create once-off migration for linking parent records
- Loading branch information
1 parent
60bd949
commit f9916a9
Showing
2 changed files
with
34 additions
and
0 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,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() |
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,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() |