feat: switch all timezone naive datetimes to timezone aware
This commit is contained in:
parent
41fc0a73a5
commit
e22abb383c
30 changed files with 322 additions and 226 deletions
|
@ -1,5 +1,8 @@
|
|||
import datetime
|
||||
import enum
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.brm.brn import BRN
|
||||
from app.extensions import db
|
||||
|
@ -13,12 +16,12 @@ class AutomationState(enum.Enum):
|
|||
|
||||
|
||||
class Automation(AbstractConfiguration):
|
||||
short_name = db.Column(db.String(25), nullable=False)
|
||||
state = db.Column(db.Enum(AutomationState), default=AutomationState.IDLE, nullable=False)
|
||||
enabled = db.Column(db.Boolean, nullable=False)
|
||||
last_run = db.Column(db.DateTime(), nullable=True)
|
||||
next_run = db.Column(db.DateTime(), nullable=True)
|
||||
next_is_full = db.Column(db.Boolean(), nullable=False)
|
||||
short_name: Mapped[str]
|
||||
state: Mapped[AutomationState] = mapped_column(default=AutomationState.IDLE)
|
||||
enabled: Mapped[bool]
|
||||
last_run: Mapped[Optional[datetime]] = mapped_column(db.DateTime(timezone=True))
|
||||
next_run: Mapped[Optional[datetime]] = mapped_column(db.DateTime(timezone=True))
|
||||
next_is_full: Mapped[bool]
|
||||
|
||||
logs = db.relationship("AutomationLogs", back_populates="automation")
|
||||
|
||||
|
@ -34,13 +37,13 @@ class Automation(AbstractConfiguration):
|
|||
|
||||
def kick(self) -> None:
|
||||
self.enabled = True
|
||||
self.next_run = datetime.datetime.utcnow()
|
||||
self.updated = datetime.datetime.utcnow()
|
||||
self.next_run = datetime.now(tz=timezone.utc)
|
||||
self.updated = datetime.now(tz=timezone.utc)
|
||||
|
||||
|
||||
class AutomationLogs(AbstractResource):
|
||||
automation_id = db.Column(db.Integer, db.ForeignKey(Automation.id), nullable=False)
|
||||
logs = db.Column(db.Text)
|
||||
automation_id: Mapped[int] = mapped_column(db.ForeignKey("automation.id"))
|
||||
logs: Mapped[str]
|
||||
|
||||
automation = db.relationship("Automation", back_populates="logs")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue