Skip to content

BDMS 170: allow well to have multiple purposes and casing materials#186

Merged
jirhiker merged 6 commits into
stagingfrom
jab-well-updates
Oct 17, 2025
Merged

BDMS 170: allow well to have multiple purposes and casing materials#186
jirhiker merged 6 commits into
stagingfrom
jab-well-updates

Conversation

@jacob-a-brown

Copy link
Copy Markdown
Contributor

Why

This PR addresses the following problem / context:

  • NM_Aquifer sometimes records multiple purposes and casing materials for a well, so new tables/relationships needed to be defined to foster DB normalization
  • the transfer scripts needed to be updated for these new tables

How

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

  • Added WellPurpose and WellCasingMaterial tables and related them to thing
  • Updated schemas and tests. The WellResponse schema just returns a list of purposes and materials, not the full objects
  • update well transfer script for the new tables

Notes

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

  • updated patch_thing to remove associated purposes/materials and add new ones if the user wants to edit them (since there's no direct CRUD access to those tables). Is this the right way to proceed?
  • the search API now uses different vectors for wells and springs because of the two new tables

@codecov-commenter

codecov-commenter commented Oct 10, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.53571% with 33 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tests/conftest.py 22.22% 28 Missing ⚠️
services/thing_helper.py 85.71% 3 Missing ⚠️
schemas/thing.py 89.47% 2 Missing ⚠️
Files with missing lines Coverage Δ
api/search.py 97.82% <100.00%> (ø)
api/thing.py 98.54% <100.00%> (ø)
db/thing.py 100.00% <100.00%> (ø)
tests/test_thing.py 100.00% <100.00%> (ø)
schemas/thing.py 97.65% <89.47%> (ø)
services/thing_helper.py 92.56% <85.71%> (ø)
tests/conftest.py 93.43% <22.22%> (ø)

Comment thread services/thing_helper.py Outdated

verify_thing_type_correspondence(thing, request)

data = payload.model_dump(exclude_unset=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we have a business use case for this currently. Lets leave it out for now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

everything else is looking good!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Remove the ability to update well_purpose?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes. updating the well_purpose and well_casing_materials should follow the same CRUD structure as all other models. just because its not in the patch payload doesn't mean it should be deleted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's only deleting the previous records and creating new ones if well_purposes is in the payload (same with well_casing_materials); if well_purposes is not in the payload nothing happens. Since a well may have many purposes, if the user changes the purposes from ["Domestic", "Irrigation"] to ["Observation"] I don't know which one to change. So rather than change an existing record I remove the existing ones and create new ones for the new purposes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rather than have this handled in the generic patch_thing function, though, I can handle these cases at the PATCH /thing/water-well/{thing_id} endpoint. That'll keep the code much cleaner and separate concerns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which, if we want to proceed with that updating method (deletion/insertion), this seems to make a lot more sense for code usability, maintainability, and readability

Comment thread services/thing_helper.py
db_table, field_name = WELL_CHILD_MODEL_MAP[child_table]
child_table_data = payload.model_dump(exclude_unset=True).pop(
child_table, None
for descriptor_table in WELL_DESCRIPTOR_MODEL_MAP.keys():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for key,value in WELL_DESCRIPTOR_MODEL_MAP.items():

Comment thread services/thing_helper.py
@jirhiker jirhiker merged commit 76438c1 into staging Oct 17, 2025
3 checks passed
@jirhiker jirhiker deleted the jab-well-updates branch October 17, 2025 19:20
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.

3 participants