mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
"""SQLModel mirror of the ``landlord_water_heating_overrides`` Drizzle table.
|
|
|
|
The schema source of truth lives in the ``assessment-model`` TS repo
|
|
(`src/app/db/schema/landlord_overrides.ts`). The migrations are owned there;
|
|
this row class only mirrors the columns so the Python lambda can read/write.
|
|
See ADR-0003. Shape mirrors ``LandlordWallTypeOverrideRow`` -- the only
|
|
differences are the table name, the ``water_heating`` pgEnum on ``value``, and
|
|
the unique-constraint name.
|
|
"""
|
|
|
|
from datetime import datetime, timezone
|
|
from typing import ClassVar
|
|
from uuid import UUID, uuid4
|
|
|
|
from sqlalchemy import BigInteger, Column, UniqueConstraint
|
|
from sqlalchemy import Enum as SAEnum
|
|
from sqlmodel import Field, SQLModel
|
|
|
|
from domain.epc.property_overrides.water_heating_type import WaterHeatingType
|
|
from infrastructure.postgres.landlord_override_enums import override_source_sa_enum
|
|
|
|
|
|
class LandlordWaterHeatingOverrideRow(SQLModel, table=True):
|
|
__tablename__: ClassVar[str] = "landlord_water_heating_overrides" # pyright: ignore[reportIncompatibleVariableOverride]
|
|
__table_args__: ClassVar[tuple[UniqueConstraint, ...]] = ( # pyright: ignore[reportIncompatibleVariableOverride]
|
|
UniqueConstraint(
|
|
"portfolio_id",
|
|
"description",
|
|
name="landlord_water_heating_overrides_portfolio_description_unique",
|
|
),
|
|
)
|
|
|
|
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
|
|
|
# bigint to match the Drizzle ``portfolio_id`` FK; SQLModel's default int
|
|
# mapping is 32-bit Integer and would overflow once portfolio IDs exceed
|
|
# 2^31. The FK to ``portfolio.id`` is enforced by the Drizzle migration,
|
|
# not declared here -- the ``portfolio`` table is not modelled in Python.
|
|
portfolio_id: int = Field(
|
|
sa_column=Column(BigInteger, nullable=False, index=True),
|
|
)
|
|
|
|
description: str = Field(nullable=False)
|
|
|
|
value: WaterHeatingType = Field(
|
|
sa_column=Column(
|
|
SAEnum(
|
|
WaterHeatingType,
|
|
name="water_heating",
|
|
values_callable=lambda cls: [m.value for m in cls], # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType, reportUnknownVariableType]
|
|
),
|
|
nullable=False,
|
|
),
|
|
)
|
|
|
|
# Shared SAEnum -- see ``landlord_override_enums`` for why this single
|
|
# instance is reused by every ``landlord_*_overrides`` row class.
|
|
source: str = Field(
|
|
sa_column=Column(override_source_sa_enum, nullable=False),
|
|
)
|
|
|
|
created_at: datetime = Field(
|
|
default_factory=lambda: datetime.now(timezone.utc),
|
|
nullable=False,
|
|
)
|
|
updated_at: datetime = Field(
|
|
default_factory=lambda: datetime.now(timezone.utc),
|
|
nullable=False,
|
|
)
|