Skip to content

Commit 4cf52de

Browse files
committed
Add migrator to change workflow_type values in data_object table
1 parent 127b48b commit 4cf52de

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Rename data object workflow types
2+
3+
The Berkeley schema migration changed a number of workflow type names. Even though
4+
the `data_object` table is truncated at the start of the ingest process, the old
5+
workflow types were being introduced by a merge operation from the production database
6+
to the ingest database.
7+
8+
See also: https://github.com/microbiomedata/nmdc-server/issues/1415
9+
10+
Revision ID: e54d37bfb90b
11+
Revises: 2ec2d0b4f840
12+
Create Date: 2024-10-11 18:06:08.521445
13+
14+
"""
15+
from typing import Optional
16+
17+
from alembic import op
18+
import sqlalchemy as sa
19+
from sqlalchemy.sql import table, column
20+
21+
22+
# revision identifiers, used by Alembic.
23+
revision: str = 'e54d37bfb90b'
24+
down_revision: Optional[str] = '2ec2d0b4f840'
25+
branch_labels: Optional[str] = None
26+
depends_on: Optional[str] = None
27+
28+
29+
WORKFLOW_TYPE_MAP = [
30+
{
31+
"old": "nmdc:MAGsAnalysisActivity",
32+
"new": "nmdc:MagsAnalysis",
33+
},
34+
{
35+
"old": "nmdc:MetabolomicsAnalysisActivity",
36+
"new": "nmdc:MetabolomicsAnalysis",
37+
},
38+
{
39+
"old": "nmdc:MetaProteomicAnalysis",
40+
"new": "nmdc:MetaproteomicAnalysis",
41+
},
42+
{
43+
"old": "nmdc:metaT",
44+
"new": "nmdc:MetatranscriptomeAnalysis",
45+
},
46+
{
47+
"old": "nmdc:NomAnalysisActivity",
48+
"new": "nmdc:NomAnalysis",
49+
},
50+
{
51+
"old": "nmdc:ReadbasedAnalysis",
52+
"new": "nmdc:ReadBasedTaxonomyAnalysis",
53+
},
54+
{
55+
"old": "nmdc:ReadQCAnalysisActivity",
56+
"new": "nmdc:ReadQcAnalysis",
57+
},
58+
]
59+
60+
61+
def upgrade():
62+
data_object = table("data_object", column("workflow_type", sa.String))
63+
for mapping in WORKFLOW_TYPE_MAP:
64+
op.execute(
65+
data_object.update()
66+
.where(data_object.c.workflow_type == mapping["old"])
67+
.values(workflow_type=mapping["new"])
68+
)
69+
70+
71+
def downgrade():
72+
data_object = table("data_object", column("workflow_type", sa.String))
73+
for mapping in WORKFLOW_TYPE_MAP:
74+
op.execute(
75+
data_object.update()
76+
.where(data_object.c.workflow_type == mapping["new"])
77+
.values(workflow_type=mapping["old"])
78+
)

0 commit comments

Comments
 (0)