-
Notifications
You must be signed in to change notification settings - Fork 4
BDMS-501: Implement read-only admin view for NMAMinorTraceChemistry #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chasetmartin
merged 12 commits into
staging
from
kas-bdms-501-admin-view-NMAMinorTraceChemistry
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c41c487
refactor: update name and label for Minor Trace Chemistry to include …
ksmuczynski 0376951
refactor: rename chemistry_sample_info_id to sample_pt_id in NMA_Mino…
ksmuczynski 6c0fa8b
refactor (models): add missing legacy fields and update column mappin…
ksmuczynski 5cea495
refactor: updated admin view reflect the renamed/added fields from th…
ksmuczynski 7af63be
fix: fixed UniqueConstraint to reference the column name SQLAlchemy e…
ksmuczynski 9487193
refactor: update admin tests to reflect 'NMA' prefix in Minor Trace C…
ksmuczynski 338abd4
refactor: add 'wclab_id' and 'object_id' to sortable fields in Minor …
ksmuczynski 34f157d
fix: align minor trace chemistry schema and tests
ksmuczynski 8dcfcb7
fix: update NMA chemistry lineage tests for sample_pt_id
ksmuczynski d7c93ec
test: update admin minor trace chemistry feature for sample_pt_id
ksmuczynski 99e2e1d
refactor: Rebase NMA minor trace migration onto new base
ksmuczynski d5db96d
fix: update field names in transfer scripts
chasetmartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
134 changes: 134 additions & 0 deletions
134
alembic/versions/3a9c1f5b7d2e_align_nma_minor_trace_columns.py
This file contains hidden or 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,134 @@ | ||
| """Align NMA_MinorTraceChemistry columns with legacy schema. | ||
|
|
||
| Revision ID: 3a9c1f5b7d2e | ||
| Revises: c1d2e3f4a5b6 | ||
| Create Date: 2026-01-31 12:00:00.000000 | ||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy import inspect | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "3a9c1f5b7d2e" | ||
| down_revision: Union[str, Sequence[str], None] = "c1d2e3f4a5b6" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def _column_names(inspector, table_name: str) -> set[str]: | ||
| return {col["name"] for col in inspector.get_columns(table_name)} | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Rename legacy columns and add missing fields.""" | ||
| bind = op.get_bind() | ||
| inspector = inspect(bind) | ||
| if not inspector.has_table("NMA_MinorTraceChemistry"): | ||
| return | ||
|
|
||
| table_name = "NMA_MinorTraceChemistry" | ||
| columns = _column_names(inspector, table_name) | ||
|
|
||
| rename_map = { | ||
| "chemistry_sample_info_id": "SamplePtID", | ||
| "sample_point_id": "SamplePointID", | ||
| "analyte": "Analyte", | ||
| "sample_value": "SampleValue", | ||
| "units": "Units", | ||
| "symbol": "Symbol", | ||
| "analysis_method": "AnalysisMethod", | ||
| "analysis_date": "AnalysisDate", | ||
| "notes": "Notes", | ||
| "analyses_agency": "AnalysesAgency", | ||
| "uncertainty": "Uncertainty", | ||
| "volume": "Volume", | ||
| "volume_unit": "VolumeUnit", | ||
| } | ||
|
|
||
| for old_name, new_name in rename_map.items(): | ||
| if old_name in columns and new_name not in columns: | ||
| op.alter_column(table_name, old_name, new_column_name=new_name) | ||
| columns.remove(old_name) | ||
| columns.add(new_name) | ||
|
|
||
| if "SamplePointID" not in columns: | ||
| op.add_column( | ||
| table_name, sa.Column("SamplePointID", sa.String(length=10), nullable=True) | ||
| ) | ||
| if "OBJECTID" not in columns: | ||
| op.add_column(table_name, sa.Column("OBJECTID", sa.Integer(), nullable=True)) | ||
| if "WCLab_ID" not in columns: | ||
| op.add_column( | ||
| table_name, sa.Column("WCLab_ID", sa.String(length=25), nullable=True) | ||
| ) | ||
|
|
||
| unique_constraints = inspector.get_unique_constraints(table_name) | ||
| unique_columns = {tuple(uc.get("column_names") or []) for uc in unique_constraints} | ||
| unique_names = {uc.get("name") for uc in unique_constraints} | ||
|
|
||
| if ( | ||
| ("OBJECTID",) not in unique_columns | ||
| and "uq_nma_minor_trace_chemistry_objectid" not in unique_names | ||
| ): | ||
| op.create_unique_constraint( | ||
| "uq_nma_minor_trace_chemistry_objectid", | ||
| table_name, | ||
| ["OBJECTID"], | ||
| ) | ||
|
|
||
| if "uq_minor_trace_chemistry_sample_analyte" not in unique_names: | ||
| op.create_unique_constraint( | ||
| "uq_minor_trace_chemistry_sample_analyte", | ||
| table_name, | ||
| ["SamplePtID", "Analyte"], | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Revert column names and remove added fields.""" | ||
| bind = op.get_bind() | ||
| inspector = inspect(bind) | ||
| if not inspector.has_table("NMA_MinorTraceChemistry"): | ||
| return | ||
|
|
||
| table_name = "NMA_MinorTraceChemistry" | ||
| columns = _column_names(inspector, table_name) | ||
|
|
||
| unique_constraints = inspector.get_unique_constraints(table_name) | ||
| unique_names = {uc.get("name") for uc in unique_constraints} | ||
|
|
||
| if "uq_nma_minor_trace_chemistry_objectid" in unique_names: | ||
| op.drop_constraint( | ||
| "uq_nma_minor_trace_chemistry_objectid", | ||
| table_name, | ||
| type_="unique", | ||
| ) | ||
|
|
||
| for column_name in ("WCLab_ID", "OBJECTID", "SamplePointID"): | ||
| if column_name in columns: | ||
| op.drop_column(table_name, column_name) | ||
|
|
||
| rename_map = { | ||
| "SamplePtID": "chemistry_sample_info_id", | ||
| "Analyte": "analyte", | ||
| "SampleValue": "sample_value", | ||
| "Units": "units", | ||
| "Symbol": "symbol", | ||
| "AnalysisMethod": "analysis_method", | ||
| "AnalysisDate": "analysis_date", | ||
| "Notes": "notes", | ||
| "AnalysesAgency": "analyses_agency", | ||
| "Uncertainty": "uncertainty", | ||
| "Volume": "volume", | ||
| "VolumeUnit": "volume_unit", | ||
| } | ||
|
|
||
| columns = _column_names(inspector, table_name) | ||
| for old_name, new_name in rename_map.items(): | ||
| if old_name in columns and new_name not in columns: | ||
| op.alter_column(table_name, old_name, new_column_name=new_name) | ||
| columns.remove(old_name) | ||
| columns.add(new_name) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.