Skip to content

kas-bdms-540-standardize-PKs-FKs#467

Merged
jirhiker merged 7 commits intostagingfrom
kas-bdms-540-standardize-PKs-FKs
Feb 6, 2026
Merged

kas-bdms-540-standardize-PKs-FKs#467
jirhiker merged 7 commits intostagingfrom
kas-bdms-540-standardize-PKs-FKs

Conversation

@ksmuczynski
Copy link
Contributor

@ksmuczynski ksmuczynski commented Feb 5, 2026

Why

This PR addresses the following problem / context:

  • Removes unnecessary Thing relationship and FK on NMA_Radionuclides and aligns admin/UI + models
  • Standardizes NMA legacy table PK/FK layout and patterns
  • Establishes missing relationship between NMA_SurfaceWaterData and Thing (via LocationId → Thing.nma_pk_location)
  • Updates SurfaceWaterData transfer to resolve thing_id via Thing.nma_pk_location (from LocationId), skipping unmatched rows and preventing orphaned child records.
  • Keeps tests/transfers aligned with the new FK requirements

How

Implementation summary - the following was changed / added / removed:

  • Remove unnecessary thing_idFK on NMA_Radionuclides as associated relationships (db/nma_legacy.py)
  • Removedthing_id from radionuclides admin view (admin/views/radionuclides.py)
  • Update db/nma_legacy.py to reorder/annotate PK/FK sections
  • Add thing_id FK + relationship/validation for NMA_SurfaceWaterData
  • Added migrations to:
    • drop thing_id from NMA_Radionuclides (alembic/versions/ d9f1e2c3b4a5_drop_thing_id_from_nma_radionuclides.py)
    • add/backfill/enforce thing_id on NMA_SurfaceWaterData (alembic/versions/c7f8a9b0c1d2_add_thing_id_to_nma_surface_water_data.py)
  • Update SurfaceWaterData legacy tests to attach Thing.nma_pk_location and set thing_id (tests/test_surface_water_data_legacy.py)
  • Adjusted surface_water_data transfer to cache Thing IDs by location, skip rows without a match, and upsert thing_id (transfers/surface_water_data.py)
  • Made Thing.nma_pk_location populate from row.LocationId during parent transfers

Notes

Any special considerations, workarounds, or follow-up work to note?

… 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.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id FK from NMA_Radionuclides table and admin views
  • Added thing_id FK to NMA_SurfaceWaterData with relationship validation
  • Standardized PK/FK layout annotations across all NMA legacy tables
  • Updated transfer logic to populate Thing.nma_pk_location and resolve thing_id via 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 jirhiker merged commit 56af195 into staging Feb 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove redundant Thing FK in NMA_Radionuclides and standardize PK/FK layout

2 participants