File size: 1,184 Bytes
2756f0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe40b87
 
 
 
2756f0f
 
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
30
import uuid
from datetime import date

from sqlalchemy import CheckConstraint, Date, ForeignKey, Index, SmallInteger, String
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column

from app.common.base_model import Base, CreatedAtMixin, IdMixin


class DrillLog(IdMixin, CreatedAtMixin, Base):
    """One logged set. day is the device's local date so "sets today" matches what the player sees."""

    __tablename__ = "drill_logs"
    __table_args__ = (
        CheckConstraint("reps BETWEEN 1 AND 8", name="reps"),
        Index("ix_drill_logs_owner_id_day", "owner_id", "day"),
    )

    owner_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("accounts.id", ondelete="CASCADE"))
    session_id: Mapped[uuid.UUID | None] = mapped_column(
        UUID(as_uuid=True), ForeignKey("sessions.id", ondelete="SET NULL")
    )
    drill_id: Mapped[str] = mapped_column(String(40))
    assignment_id: Mapped[uuid.UUID | None] = mapped_column(
        UUID(as_uuid=True), ForeignKey("drill_assignments.id", ondelete="SET NULL")
    )
    reps: Mapped[int] = mapped_column(SmallInteger)
    day: Mapped[date] = mapped_column(Date)