Merged
Conversation
… relationships across NMA tables - Remove the unnecessary thing relationship from NMA_Radionuclides and eliminate duplicate definitions - Create sections to explicitly note PK/FK and Legacy PK/ Legacy FK information
…WaterData` and `Thing` - Add thing_id foreign key to NMA_SurfaceWaterData - update `surface_water_data/py` transfer script
…id and location_id - Updated the surface water legacy tests to attach a Thing with a matching nma_pk_location before inserting NMA_SurfaceWaterData, keeping the fixture and logic localized to these tests.
Drop Radionuclides thing_id before adding SurfaceWaterData FK
…rData to Things - Made Thing.nma_pk_location populate from row.LocationId during parent transfers - SurfaceWaterData transfer now resolves thing_id via Thing.nma_pk_location (from LocationId), skipping unmatched rows and preventing orphaned child records.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes primary key and foreign key patterns across NMA legacy tables and establishes the missing relationship between NMA_SurfaceWaterData and Thing. The changes remove an incorrect FK from NMA_Radionuclides, add a required FK to NMA_SurfaceWaterData, and ensure all parent transfers populate Thing.nma_pk_location for proper linkage.
Changes:
- Removed unnecessary
thing_idFK fromNMA_Radionuclidestable and admin views - Added
thing_idFK toNMA_SurfaceWaterDatawith relationship validation - Standardized PK/FK layout annotations across all NMA legacy tables
- Updated transfer logic to populate
Thing.nma_pk_locationand resolvething_idvia location mapping
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| db/nma_legacy.py | Removed thing_id FK from NMA_Radionuclides, added thing_id FK to NMA_SurfaceWaterData, and reorganized all table definitions with standardized PK/FK section comments |
| db/thing.py | Removed radionuclides relationship and added surface_water_data relationship to Thing model |
| transfers/surface_water_data.py | Added Thing ID caching, lookup logic via nma_pk_location, and skipping of rows without matching Things |
| transfers/well_transfer.py | Added nma_pk_location population from row.LocationId for well Things |
| transfers/thing_transfer.py | Added nma_pk_location population from row.LocationId for generic Things |
| tests/test_surface_water_data_legacy.py | Updated all test fixtures to create Things with nma_pk_location and set thing_id on surface water records |
| admin/views/radionuclides.py | Removed thing_id from column lists and labels |
| alembic/versions/d9f1e2c3b4a5_drop_thing_id_from_nma_radionuclides.py | Migration to drop thing_id column and constraints from NMA_Radionuclides |
| alembic/versions/c7f8a9b0c1d2_add_thing_id_to_nma_surface_water_data.py | Migration to add, backfill, and enforce thing_id on NMA_SurfaceWaterData |
jirhiker
approved these changes
Feb 6, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
This PR addresses the following problem / context:
NMA_Radionuclidesand aligns admin/UI + modelsNMA_SurfaceWaterDataandThing(via LocationId → Thing.nma_pk_location)How
Implementation summary - the following was changed / added / removed:
thing_idFK onNMA_Radionuclidesas associated relationships (db/nma_legacy.py)thing_idfrom radionuclides admin view (admin/views/radionuclides.py)db/nma_legacy.pyto reorder/annotate PK/FK sectionsthing_idFK + relationship/validation forNMA_SurfaceWaterDataSurfaceWaterDatalegacy tests to attach Thing.nma_pk_location and set thing_id (tests/test_surface_water_data_legacy.py)surface_water_datatransfer to cache Thing IDs by location, skip rows without a match, and upsert thing_id (transfers/surface_water_data.py)Thing.nma_pk_locationpopulate fromrow.LocationIdduring parent transfersNotes
Any special considerations, workarounds, or follow-up work to note?
NMA_Radionuclidesand standardize PK/FK layout #461