-
Notifications
You must be signed in to change notification settings - Fork 4
BDMS-221-225: New measuring_point_history model #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jacob-a-brown
merged 5 commits into
bdms-221
from
kas-bdms-221-225-core-well-info-models-schemas
Nov 12, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e87150a
feat: create new `measuring_point_history` model.
ksmuczynski 545c2e8
feat: add new relationship to `Thing` model.
ksmuczynski 15c770f
refactor: add new field to `measuring_point_history` model.
ksmuczynski 35051be
Merge branch 'bdms-221' into kas-bdms-221-225-core-well-info-models-s…
ksmuczynski 8d1d8fa
refactor: update 'measuring_point_history' model.
ksmuczynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """ | ||
| SQLAlchemy model for the MeasuringPointHistory table. | ||
|
|
||
| This table stores the authoritative MP height of a Thing from | ||
| construction or modification events. It provides a complete, auditable | ||
| history of the official, surveyed measuring point (MP) descriptions | ||
| and heights for a Thing. | ||
|
|
||
| This table is not for storing routine field checks of the | ||
| MP height (which are stored on the `Observation` table). This table should | ||
| only be updated when a well is first installed, physically modified | ||
| (e.g., a new wellhead is installed), or officially re-surveyed. | ||
| """ | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from sqlalchemy import Integer, ForeignKey, Date, Text, Numeric | ||
| from sqlalchemy.orm import relationship, Mapped, mapped_column | ||
|
|
||
| from db.base import Base, AutoBaseMixin, ReleaseMixin | ||
|
|
||
| if TYPE_CHECKING: | ||
| from db.thing import Thing | ||
|
|
||
|
|
||
| class MeasuringPointHistory(Base, AutoBaseMixin, ReleaseMixin): | ||
| """ | ||
| Represents a single, authoritative, time-stamped record of a | ||
| Thing's measuring point description and height. | ||
| """ | ||
|
|
||
| # --- Foreign Keys --- | ||
| thing_id: Mapped[int] = mapped_column( | ||
| Integer, ForeignKey("thing.id", ondelete="CASCADE"), nullable=False | ||
| ) | ||
|
|
||
| # --- Columns --- | ||
| measuring_point_height: Mapped[float] = mapped_column( | ||
| Numeric, | ||
| nullable=False, | ||
| comment="The official, surveyed height of the measuring point relative to ground surface (in feet).", | ||
| ) | ||
| measuring_point_description: Mapped[str] = mapped_column( | ||
| Text, | ||
| nullable=True, | ||
| comment="A clear description of the measuring point (e.g., 'North side of casing, top of PVC', 'Top of new steel collar').", | ||
| ) | ||
| start_date: Mapped[Date] = mapped_column( | ||
| Date, | ||
| nullable=False, | ||
| comment="The date this measuring point configuration became effective.", | ||
| ) | ||
| end_date: Mapped[Date] = mapped_column( | ||
| Date, | ||
| nullable=True, | ||
| comment="The date this measuring point configuration was superseded. A `NULL` value indicates this is the current, active, and authoritative record for the `Thing`.", | ||
| ) | ||
|
|
||
| reason: Mapped[str] = mapped_column( | ||
| Text, | ||
| nullable=True, | ||
| comment="Describes the reason for the new or updated measuring point (e.g., 'A new wellhead was installed').", | ||
| ) | ||
|
|
||
| # --- Relationships --- | ||
| # Many-To-One: A description history record belongs to one Thing. Many history records may belong to a single Thing. | ||
| thing: Mapped["Thing"] = relationship("Thing", back_populates="measuring_points") |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this model only pertains to the
thingmodel I don't think that it needs to go into its own file. It can go intodb/thing.pyUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to do this. Just curious, how are we deciding which models get their own files? When I'm looking for info about a table/model, I'm expecting it to be listed in the
dbdirectory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we have a standard, but when making a new model I put it into an existing file if it only pertains to other models in that file (e.g.
WellPurposeandWellCasingMaterial). [Now that I think of it, I don't know if I've created a standalone model, but it makes sense for me to have the polymorphic models be in their own files for ease of understanding.]There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what @jirhiker thoughts are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jirhiker I merged this so I can use develop off of it - where the table is defined in the codebase won't affect how it's used in the schemas/tests. If you think it should be in the
db/thing.pyfile I can move it there easily.