import uuid from sqlalchemy import Enum, ForeignKey, String from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin from app.models.department import Department from app.models.enums import UserRole class User(UUIDPrimaryKeyMixin, TimestampMixin, Base): __tablename__ = "users" email: Mapped[str] = mapped_column(String(320), unique=True, index=True) name: Mapped[str] = mapped_column(String(200)) role: Mapped[UserRole] = mapped_column( Enum(UserRole, native_enum=False, length=32), default=UserRole.member ) password_hash: Mapped[str] = mapped_column(String(255)) # Interface language. NULL follows the browser's Accept-Language; a value # pins it. One column rather than a preferences table: this is the only # preference that has to follow the person across devices — the theme is # per-device and lives in localStorage. locale: Mapped[str | None] = mapped_column(String(5)) department_id: Mapped[uuid.UUID | None] = mapped_column( ForeignKey("departments.id", ondelete="SET NULL") ) department: Mapped[Department | None] = relationship(lazy="joined")