-
Notifications
You must be signed in to change notification settings - Fork 3
feat: create new Deployment model #144
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3f97044
feat: create new Deployment model
ksmuczynski 1a01fd9
refactor: modify `mapped_column` for `recording_interval` field
ksmuczynski c22fd2b
feat: add `deployment` relationship and proxy to `Thing` model
ksmuczynski 441a5ea
feat: add `deployment` relationship and `thing` proxy to the `Sensor`…
ksmuczynski 9b2ed77
refactor: import necessary classes to `Sensor` model so they can be f…
ksmuczynski 5ae8094
refactor: update foreign key names in `Deployment` table
ksmuczynski 7ff9e15
feat: add `deployment` model to `__init__` file so mappers can be con…
ksmuczynski f4ffb6c
refactor: update proxy name in `Thing` table from `sensor` to `sensors`.
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
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,47 @@ | ||
| """ | ||
| This table is an installation log that creates a many-to-many relationship | ||
| between Things and Sensors, tracking which piece of hardware was installed | ||
| at which Thing and for what period of time. | ||
| """ | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from sqlalchemy import Integer, ForeignKey, Date, Numeric, Text | ||
| from sqlalchemy.orm import relationship, Mapped, mapped_column | ||
|
|
||
| from db.base import Base, AutoBaseMixin, ReleaseMixin, lexicon_term | ||
|
|
||
| if TYPE_CHECKING: | ||
| from db.thing import Thing | ||
| from db.sensor import Sensor | ||
|
|
||
|
|
||
| class Deployment(Base, AutoBaseMixin, ReleaseMixin): | ||
| """ | ||
| Represents the installation of a specific piece of equipment (Sensor) at a Thing | ||
| for a defined period. This is an Association Object. | ||
| """ | ||
|
|
||
| # --- Foreign Keys --- | ||
| thing_id: Mapped[int] = mapped_column( | ||
| Integer, ForeignKey("thing.id"), nullable=False | ||
| ) | ||
| sensor_id: Mapped[int] = mapped_column( | ||
| Integer, ForeignKey("sensor.id"), nullable=False | ||
| ) | ||
|
|
||
| # --- Columns --- | ||
| installation_date: Mapped[Date] = mapped_column(Date, nullable=False) | ||
| removal_date: Mapped[Date] = mapped_column(Date, nullable=True) | ||
| recording_interval: Mapped[int] = mapped_column(Integer, nullable=True) | ||
| recording_interval_units: Mapped[str] = lexicon_term(nullable=True) | ||
| hanging_cable_length: Mapped[float] = mapped_column(Numeric, nullable=True) | ||
| hanging_point_height: Mapped[float] = mapped_column(Numeric, nullable=True) | ||
| hanging_point_description: Mapped[str] = mapped_column(Text, nullable=True) | ||
| notes: Mapped[str] = mapped_column(Text, nullable=True) | ||
|
|
||
| # --- Relationships --- | ||
| # Many-To-One: A Deployment is for one Thing. | ||
| thing: Mapped["Thing"] = relationship("Thing", back_populates="deployments") | ||
| # Many-To-One: A Deployment is of one piece of equipment (sensor). | ||
| sensor: Mapped["Sensor"] = relationship("Sensor", back_populates="deployments") | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.