- Update session-context.md with exact resume point for next session - Update settings.local.json with broader git permissions - feature/grundstruktur merged to develop - PAT authentication configured Version: 0.2.3
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import uuid
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import DateTime, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class Tenant(Base):
|
|
__tablename__ = "tenants"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
primary_key=True, default=uuid.uuid4, index=True
|
|
)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
slug: Mapped[str] = mapped_column(String(100), unique=True, nullable=False, index=True)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
onupdate=lambda: datetime.now(timezone.utc),
|
|
nullable=False,
|
|
)
|
|
|
|
# Relationships
|
|
user_tenants: Mapped[list["UserTenant"]] = relationship( # noqa: F821
|
|
"UserTenant", back_populates="tenant", cascade="all, delete-orphan"
|
|
)
|
|
beds: Mapped[list["Bed"]] = relationship( # noqa: F821
|
|
"Bed", back_populates="tenant", cascade="all, delete-orphan"
|
|
)
|
|
plants: Mapped[list["Plant"]] = relationship( # noqa: F821
|
|
"Plant", back_populates="tenant"
|
|
)
|