Skip to content

BDMS-227-254: add schema validations to aquifer and geology schemas#266

Merged
ksmuczynski merged 5 commits into
bdms-227from
kas-227-254-add-schema-validations-aquifer-geology
Dec 2, 2025
Merged

BDMS-227-254: add schema validations to aquifer and geology schemas#266
ksmuczynski merged 5 commits into
bdms-227from
kas-227-254-add-schema-validations-aquifer-geology

Conversation

@ksmuczynski

Copy link
Copy Markdown
Contributor

Why

This PR addresses the following problem / context:

  • Data Integrity: Currently, there are no checks to ensure that depth intervals are logical (i.e., bottom_depth > top_depth) or that spatial boundaries are valid WKT strings.
  • Missing Functionality: There was no Pydantic schema available to handle the creation of ThingGeologicFormationAssociation records.
  • Loose Typing: Input strings for fields like primary_aquifer_type or lithology were not strictly validated against their respective controlled vocabularies, leading to potential data inconsistencies (e.g., casing mismatches).

How

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

New Validators Module: Created schemas/validators.py containing reusable mixins:
- DepthIntervalMixin: Enforces that bottom_depth > top_depth and depths are non-negative.
- GeometryMixin: Validates boundary fields
- validate_enum_input: A helper function to validate inputs against Enums case-insensitively.

Geologic Formations:

  • Added CreateThingGeologicFormationAssociation schema to schemas_geologic_formation.py using the DepthIntervalMixin.
  • Updated CreateGeologicFormation to enforce uppercasing on formation_code and Enum validation on lithology.

Aquifer Systems:

  • Updated CreateAquiferSystem in schemas_aquifer_system.py to enforce AquiferType and GeographicScale Enum validation.
  • Added GeometryMixin to CreateAquiferSystem for WKT boundary validation.

Notes

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

  • Design decisions: Shared validation logic was placed in a dedicated schemas/validators.py file rather than init.py to maintain clean separation of concerns and prevent circular import issues.

…on create model

- Add `schemas/validators.py` with `DepthIntervalMixin` for logical depth checks, `GeometryMixin` for WKT validation, and `validate_enum_input` for validation.
- Add `CreateThingGeologicFormationAssociation` to `schemas_geologic_formation.py` to support creation of formation picks/stratigraphy.
- Update `CreateGeologicFormation` to enforce uppercase formation codes and validate WKT boundaries.
- Update `CreateAquiferSystem` to validate WKT boundaries.
Comment thread schemas/validators.py Outdated
Comment thread schemas/validators.py
Comment thread schemas/validators.py Outdated
Comment thread schemas/validators.py Outdated
Comment thread schemas/validators.py Outdated
Comment thread schemas/geologic_formation.py Outdated
- Delegate WKT boundary validation to `services/validation/geospatial.py` to enforce topological validity.
- Update `CreateAquiferSystem` and `CreateGeologicFormation` to enforce strict Enum typing for controlled vocabularies, removing loose string coercion.
`top_depth` and `bottom_depth` are required so the None check is redundant.

Remove the None check.
- Remove manual `if` validation logic for non-negative depths in `DepthIntervalMixin`.
- Implement `Field(ge=0)` on `top_depth` and `bottom_depth` to leverage Pydantic's native schema validation and cleaner OpenAPI generation.
- Ensure `CreateThingGeologicFormationAssociation` inherits these constraints by explicitly redefining fields with `ge=0`.
…chema-validations

# Conflicts:
#	schemas/aquifer_system.py
@ksmuczynski ksmuczynski merged commit 09b4b73 into bdms-227 Dec 2, 2025
4 checks passed
@ksmuczynski ksmuczynski deleted the kas-227-254-add-schema-validations-aquifer-geology branch December 10, 2025 18:24
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.

2 participants