Skip to content

Commit c89313e

Browse files
authored
Merge pull request #1723 from microbiomedata/issue-1722-submission-schema-11.10.0-rc.1
Upgrade to nmdc-submission-schema v11.10.0-rc.1
2 parents 67cdd93 + 83d47e1 commit c89313e

File tree

3 files changed

+123
-13
lines changed

3 files changed

+123
-13
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
"""Update JGI submission-schema slot names
2+
3+
Revision ID: 0cb677fa8d5e
4+
Revises: e27443f0837e
5+
Create Date: 2025-08-06 19:53:09.430148
6+
7+
"""
8+
9+
from collections import namedtuple
10+
from typing import Optional
11+
from uuid import uuid4
12+
13+
from alembic import op
14+
from sqlalchemy import Column, orm
15+
from sqlalchemy.dialects.postgresql import JSONB, UUID
16+
from sqlalchemy.ext.declarative import declarative_base
17+
18+
# revision identifiers, used by Alembic.
19+
revision: str = "0cb677fa8d5e"
20+
down_revision: Optional[str] = "e27443f0837e"
21+
branch_labels: Optional[str] = None
22+
depends_on: Optional[str] = None
23+
24+
25+
Base = declarative_base()
26+
27+
28+
class SubmissionMetadata(Base):
29+
__tablename__ = "submission_metadata"
30+
31+
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4)
32+
metadata_submission = Column(JSONB, nullable=False)
33+
34+
35+
RenamedSlot = namedtuple("RenamedSlot", ["old_name_mg", "old_name_mt", "new_name"])
36+
37+
38+
RENAMED_SLOTS: list[RenamedSlot] = [
39+
RenamedSlot("dna_absorb1", "rna_absorb1", "nuc_acid_absorb1"),
40+
RenamedSlot("dna_absorb2", "rna_absorb2", "nuc_acid_absorb2"),
41+
RenamedSlot("dna_concentration", "rna_concentration", "nuc_acid_concentration"),
42+
RenamedSlot("dna_cont_type", "rna_cont_type", "cont_type"),
43+
RenamedSlot("dna_cont_well", "rna_cont_well", "cont_well"),
44+
RenamedSlot("dna_container_id", "rna_container_id", "container_name"),
45+
RenamedSlot("dna_dnase", "dnase_rna", "dnase"),
46+
RenamedSlot("dna_samp_id", "rna_samp_id", "jgi_samp_id"),
47+
RenamedSlot("dna_sample_format", "rna_sample_format", "jgi_sample_format"),
48+
RenamedSlot("dna_sample_name", "rna_sample_name", "jgi_sample_name"),
49+
RenamedSlot("dna_seq_project", "rna_seq_project", "jgi_seq_project"),
50+
RenamedSlot("dna_seq_project_name", "rna_seq_project_name", "jgi_seq_project_name"),
51+
RenamedSlot("dna_volume", "rna_volume", "jgi_sample_volume"),
52+
]
53+
54+
55+
def upgrade():
56+
session = orm.Session(bind=op.get_bind())
57+
mappings = []
58+
for submission_metadata in session.query(SubmissionMetadata):
59+
metadata_submission = submission_metadata.metadata_submission
60+
61+
if isinstance(metadata_submission, list):
62+
continue
63+
64+
sample_data = metadata_submission.get("sampleData")
65+
66+
if sample_data is None or not isinstance(sample_data, dict):
67+
print(f"WARNING: sampleData not in migratable format for {submission_metadata.id}")
68+
continue
69+
70+
for tab_key, rows in sample_data.items():
71+
if not isinstance(rows, list):
72+
continue
73+
for row in rows:
74+
if not isinstance(row, dict):
75+
continue
76+
for rename in RENAMED_SLOTS:
77+
if "jgi_mg" in tab_key and rename.old_name_mg in row:
78+
row[rename.new_name] = row.pop(rename.old_name_mg)
79+
elif "jgi_mt" in tab_key and rename.old_name_mt in row:
80+
row[rename.new_name] = row.pop(rename.old_name_mt)
81+
82+
mappings.append({"id": submission_metadata.id, "metadata_submission": metadata_submission})
83+
84+
session.bulk_update_mappings(SubmissionMetadata, mappings)
85+
session.commit()
86+
87+
88+
def downgrade():
89+
session = orm.Session(bind=op.get_bind())
90+
mappings = []
91+
for submission_metadata in session.query(SubmissionMetadata):
92+
metadata_submission = submission_metadata.metadata_submission
93+
94+
if isinstance(metadata_submission, list):
95+
continue
96+
97+
sample_data = metadata_submission.get("sampleData")
98+
99+
if sample_data is None or not isinstance(sample_data, dict):
100+
print(f"WARNING: sampleData not in migratable format for {submission_metadata.id}")
101+
continue
102+
103+
for tab_key, rows in sample_data.items():
104+
if not isinstance(rows, list):
105+
continue
106+
for row in rows:
107+
if not isinstance(row, dict):
108+
continue
109+
for rename in RENAMED_SLOTS:
110+
if rename.new_name in row:
111+
if "jgi_mg" in tab_key:
112+
row[rename.old_name_mg] = row.pop(rename.new_name)
113+
elif "jgi_mt" in tab_key:
114+
row[rename.old_name_mt] = row.pop(rename.new_name)
115+
116+
mappings.append({"id": submission_metadata.id, "metadata_submission": metadata_submission})
117+
118+
session.bulk_update_mappings(SubmissionMetadata, mappings)
119+
session.commit()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ dependencies = [
9797
"mypy==1.11.2",
9898
"mypy-extensions==1.0.0",
9999
"nmdc-schema==11.9.1",
100-
"nmdc-submission-schema==11.9.1",
100+
"nmdc-submission-schema==11.10.0-rc.1",
101101
"nmdc-geoloc-tools==0.2.0",
102102
"openpyxl==3.1.5",
103103
"packaging==24.1",

web/src/views/SubmissionPortal/HarmonizerView.vue

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,9 @@ const TYPE_FIELD = ANALYSIS_TYPE;
9292
const COMMON_COLUMNS = [SAMP_NAME, SOURCE_MAT_ID, ANALYSIS_TYPE];
9393
9494
const ALWAYS_READ_ONLY_COLUMNS = [
95-
'dna_seq_project',
96-
'rna_seq_project',
97-
'dna_samp_id',
98-
'rna_samp_id',
99-
'rna_seq_project_pi',
100-
'dna_seq_project_pi',
101-
'dna_project_contact',
102-
'rna_project_contact',
103-
'proposal_rna',
104-
'proposal_dna',
105-
'rna_seq_project_name',
106-
'dna_seq_project_name',
95+
'jgi_seq_project',
96+
'jgi_samp_id',
97+
'jgi_seq_project_name',
10798
];
10899
109100
export default defineComponent({

0 commit comments

Comments
 (0)