Skip to content

feat: fix water elevation units to feet in materialized view and update related tests#590

Merged
jirhiker merged 1 commit intostagingfrom
water-elevation-layer
Mar 10, 2026
Merged

feat: fix water elevation units to feet in materialized view and update related tests#590
jirhiker merged 1 commit intostagingfrom
water-elevation-layer

Conversation

@jirhiker
Copy link
Copy Markdown
Member

Why

This PR addresses the following problem / context:

  • Use bullet points here

How

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

  • Use bullet points here

Notes

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

  • Use bullet points here

Copilot AI review requested due to automatic review settings March 10, 2026 06:05
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3e4fde51a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +73 to +74
((l.elevation * {METERS_TO_FEET}) - lo.depth_to_water_below_ground_surface)
AS water_elevation,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Normalize depth units before subtracting from feet elevation

In _create_water_elevation_view, water_elevation now converts l.elevation to feet but subtracts depth_to_water_below_ground_surface without unit normalization, so any groundwater observation stored in meters (o.unit = 'm') will produce a mixed-unit result (feet minus meters) and an incorrect elevation. This regression is user-impacting wherever groundwater-level records are not already in feet, so the expression should convert depth based on o.unit (or explicitly constrain to feet-only data).

Useful? React with 👍 / 👎.



def downgrade() -> None:
op.execute(text("DROP MATERIALIZED VIEW IF EXISTS ogc_water_elevation_wells"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore previous view definition in downgrade

The migration's downgrade() only drops ogc_water_elevation_wells, so rolling back from this revision leaves the database at revision m6f7a8b9c0d1 without the view that revision expects, breaking rollback consistency and any features/commands that query or refresh that materialized view after a downgrade. The downgrade path should recreate the prior view definition instead of deleting it outright.

Useful? React with 👍 / 👎.

@jirhiker jirhiker merged commit d8b3f71 into staging Mar 10, 2026
12 checks passed
Copy link
Copy Markdown
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 fixes a unit mismatch in the ogc_water_elevation_wells materialized view. Previously, the water elevation was computed as elevation - depth_to_water, which mixed meters (elevation from the Location table) with feet (depth-to-water from observations). The fix converts elevation to feet before the subtraction: (elevation_m * 3.28084) - depth_to_water_ft.

Changes:

  • New Alembic migration that drops and recreates the ogc_water_elevation_wells materialized view with the meters-to-feet conversion applied to elevation before computing water_elevation
  • Updated test assertion to validate the new formula using the conversion factor

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
alembic/versions/n7a8b9c0d1e2_fix_water_elevation_units_to_feet.py New migration that recreates the materialized view with (elevation * 3.28084) - depth_to_water formula for consistent feet output
tests/test_ogc.py Updated expected water elevation calculation to match the new conversion formula

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +121 to +122
def downgrade() -> None:
op.execute(text("DROP MATERIALIZED VIEW IF EXISTS ogc_water_elevation_wells"))
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The downgrade() only drops the materialized view, but since this migration modifies an existing view (created by m6f7a8b9c0d1), the downgrade should recreate the previous version of the view (the one without the meters-to-feet conversion). Simply dropping the view leaves the database without ogc_water_elevation_wells entirely after a downgrade, which would break any code that depends on it (e.g., cli/cli.py refreshes, pygeoapi collection endpoints, etc.).

The downgrade should drop the current view and then recreate the original view definition from m6f7a8b9c0d1 (using l.elevation - ro.depth_to_water_below_ground_surface without the conversion factor), along with the original comment and unique index.

Copilot uses AI. Check for mistakes.
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