File size: 1,091 Bytes
de1e3fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | from __future__ import annotations
from sqlalchemy import Enum as SAEnum, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from .base import Base, TimestampMixin, UserRole
class User(Base, TimestampMixin):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
dataset_id: Mapped[int | None] = mapped_column(
ForeignKey("datasets.id"), nullable=True, index=True
)
name: Mapped[str] = mapped_column(String(120))
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
phone: Mapped[str | None] = mapped_column(String(40), nullable=True)
zip: Mapped[str] = mapped_column(String(10))
# null for anonymous-only / finders without a usable login
password_hash: Mapped[str | None] = mapped_column(String(255), nullable=True)
role: Mapped[UserRole] = mapped_column(
SAEnum(UserRole, native_enum=False), default=UserRole.owner
)
dogs: Mapped[list["KnownDog"]] = relationship( # noqa: F821
back_populates="owner", cascade="all, delete-orphan"
)
|