41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
|
|
import uuid
|
||
|
|
from datetime import date, datetime, timezone
|
||
|
|
|
||
|
|
from sqlalchemy import Date, DateTime, ForeignKey, Integer, Numeric, Text, func
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
|
|
||
|
|
from app.db.base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class BedPlanting(Base):
|
||
|
|
__tablename__ = "bed_plantings"
|
||
|
|
|
||
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
primary_key=True, default=uuid.uuid4, index=True
|
||
|
|
)
|
||
|
|
bed_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("beds.id", ondelete="CASCADE"),
|
||
|
|
nullable=False,
|
||
|
|
index=True,
|
||
|
|
)
|
||
|
|
plant_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("plants.id", ondelete="RESTRICT"),
|
||
|
|
nullable=False,
|
||
|
|
index=True,
|
||
|
|
)
|
||
|
|
area_m2: Mapped[float | None] = mapped_column(Numeric(5, 2), nullable=True)
|
||
|
|
count: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||
|
|
planted_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
||
|
|
removed_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
||
|
|
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
|
|
|
||
|
|
created_at: Mapped[datetime] = mapped_column(
|
||
|
|
DateTime(timezone=True),
|
||
|
|
server_default=func.now(),
|
||
|
|
nullable=False,
|
||
|
|
)
|
||
|
|
|
||
|
|
# Relationships
|
||
|
|
bed: Mapped["Bed"] = relationship("Bed", back_populates="plantings") # noqa: F821
|
||
|
|
plant: Mapped["Plant"] = relationship("Plant", back_populates="plantings") # noqa: F821
|