"""Tenant model.""" from __future__ import annotations import uuid from datetime import datetime from sqlalchemy import CheckConstraint, DateTime, String, func from sqlalchemy.dialects.postgresql import UUID as PGUUID from sqlalchemy.orm import Mapped, mapped_column from app.core.db import Base class Tenant(Base): """Tenant entity — top-level organisational unit.""" __tablename__ = "tenants" id: Mapped[uuid.UUID] = mapped_column( PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4 ) name: Mapped[str] = mapped_column(String(200), nullable=False) slug: Mapped[str] = mapped_column(String(100), unique=True, nullable=False, index=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now() ) resolution_strategy: Mapped[str] = mapped_column( String(30), nullable=False, default="highest_wins" ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now(), onupdate=func.now() ) __table_args__ = ( # ⚠️ Only highest_wins strategy supported — other strategies removed as they were no-ops. CheckConstraint( "resolution_strategy IN ('highest_wins')", name="ck_tenant_resolution_strategy", ), )