Each child is assigned a unique permanent tv_token on creation. The TV dashboard URL (/tv/:tvToken) and WebSocket (/ws/:tvToken) now use this token instead of the internal DB ID. Existing children are backfilled on startup. README updated to reflect the change. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
from datetime import date
|
|
from sqlalchemy import String, Boolean, ForeignKey, Date, Integer
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from typing import Optional
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class Child(TimestampMixin, Base):
|
|
__tablename__ = "children"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
birth_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
color: Mapped[str] = mapped_column(String(7), default="#4F46E5") # hex color for UI
|
|
strikes: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
|
strikes_last_reset: Mapped[Optional[date]] = mapped_column(Date, nullable=True, default=None)
|
|
tv_token: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, unique=True)
|
|
|
|
user: Mapped["User"] = relationship("User", back_populates="children") # noqa: F821
|
|
daily_sessions: Mapped[list["DailySession"]] = relationship( # noqa: F821
|
|
"DailySession", back_populates="child", passive_deletes=True
|
|
)
|
|
activity_logs: Mapped[list["ActivityLog"]] = relationship( # noqa: F821
|
|
"ActivityLog", back_populates="child", passive_deletes=True
|
|
)
|