File size: 1,513 Bytes
fe40b87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
import uuid
from datetime import date

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

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


def _owner() -> Mapped[uuid.UUID]:
    return mapped_column(UUID(as_uuid=True), ForeignKey("accounts.id", ondelete="CASCADE"))


class ArmOuting(IdMixin, CreatedAtMixin, Base):
    """A game pitch count the player logged. local_date is the player's calendar day."""

    __tablename__ = "arm_outings"
    __table_args__ = (
        CheckConstraint("pitches BETWEEN 1 AND 200", name="pitches"),
        CheckConstraint("source IN ('game')", name="source"),
        Index("ix_arm_outings_owner_id_local_date", "owner_id", text("local_date DESC")),
    )

    owner_id: Mapped[uuid.UUID] = _owner()
    local_date: Mapped[date] = mapped_column(Date)
    pitches: Mapped[int] = mapped_column(SmallInteger)
    source: Mapped[str] = mapped_column(String(8), server_default="game")


class ArmFeel(IdMixin, CreatedAtMixin, Base):
    """Arm-feel reports; the newest one is the current feel."""

    __tablename__ = "arm_feel_events"
    __table_args__ = (
        CheckConstraint("feel IN ('sore', 'tight', 'good')", name="feel"),
        Index("ix_arm_feel_events_owner_id_created_at", "owner_id", text("created_at DESC")),
    )

    owner_id: Mapped[uuid.UUID] = _owner()
    feel: Mapped[str] = mapped_column(String(8))