Repository navigation
refactor(db): rename permission_history to site_activity_consent (BDMS-1381) - #1037
Open
ksmuczynski wants to merge 4 commits into
Open
ksmuczynski wants to merge 4 commits into
ksmuczynski wants to merge 4 commits into
Conversation
ADR5 uses "permission" for what staff are allowed to do, which is what permission_grant records. permission_history records whether a landowner lets the Bureau measure water levels, sample water chemistry, or install a datalogger at their site. That is consent, so the table becomes site_activity_consent, its columns become activity and allowed, and the model becomes SiteActivityConsent. The lexicon category for those activities changes from permission_type to site_activity. activity_type was the obvious name, but permission_grant already uses it as the category for data_type. The migration is hand-written. Alembic autogenerate would drop the old table and create a new one, deleting every consent on record (about 7,000 on staging). The migration reads constraint names from the catalog because PostgreSQL 18 names NOT NULL constraints and 17 does not. A guard stops the upgrade if anything on the table still has "permission" in its name. The view ogc_internal_water_well_field_operations needs no changes. PostgreSQL tracks tables by OID and columns by position, so the view follows the rename. The well API still sends permissions, permission_type and permission_allowed through serialization aliases, so OcotilloUI does not change. Renaming those fields needs a staged release and is a separate decision. The SiteActivity enum is built from core/lexicon.json, so the API does not depend on the data migration that renames the category row in existing databases. That migration overwrites the category description even if someone edited it, because the old text describes the old concept. Refs BDMS-1381
ADR5 proposed field_access_consent as the table and model name, but I chose site_activity_consent. "Field" already means a column in ADR5. "Access" is too narrow for installing a datalogger and collides with the lexicon's Access Status. ADR5 now uses the new name throughout, and a dated amendment under Status explains the change. The latest copy of the field operations view's SQL, in migration a3b4c5d6e7f8, still uses the old table and column names. The layer doc now warns that the next migration to rebuild the view must switch to the new names. Refs BDMS-1381
I edited the ERD by hand instead of regenerating it. On the current staging branch, scripts/generate_erd.py fails on an Identity column in an NMA legacy model before it reaches the renamed table. The committed ERD is also missing several newer tables, so a full regeneration would bury this change among unrelated ones. Refs BDMS-1381
The three site_activity definitions began with "Permissions for ...". These activities are what an owner consents to, and "permission" now means what staff may do. One also had its words out of order: "Permissions for water taking chemistry samples". init_lexicon never updates an existing term's definition, so a data migration rewrites the rows in existing databases. It only changes a definition that still matches the old seed text, so anything edited through /lexicon stays as it is. Data migration 20260901_0001 follows the same rule for category descriptions. Refs BDMS-1381
ksmuczynski
requested review from
jacob-a-brown,
jirhiker and
likithabommasani21
November 4, 2026 20:46
Contributor
Coverage✅ 81.45% total — gate is 75%. Coverage for the Python files changed in this PR
|
This branch has not been deployed
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.
Summary
The database now stores owner consent in
site_activity_consent, with columnsactivityandallowed. The only table whose name still says "permission" ispermission_grant, which records what staff may do. The well API, the OGC layers and OcotilloUI see no change.Why
This PR addresses the following problem / context:
permission_grantmerged, two tables used "permission" for two different things. ADR5 uses "permission" only for what staff are allowed to do, and "consent" for what a landowner allows at their site.How
Implementation summary - the following was changed / added / removed:
652b0abb3241.permission_typelexicon category tosite_activityand reworded its three term definitions, with data migrations for existing databases.Notes
Any special considerations, workarounds, or follow-up work to note?
20261102_0001_rename_permission_type_lexicon_categoryand20261102_0002_reword_site_activity_term_definitionsthrough the Data Migrations workflow. Until then the lexicon endpoints show the old category name and definitions. The API doesn't depend on either. .permissions,permission_typeandpermission_allowed, andtests/test_site_activity_consent_schema.pyfails if either alias is lost. Renaming those fields is a separate, staged change.Refs BDMS-1381