| from __future__ import annotations |
|
|
| from datetime import datetime |
| from typing import Any |
|
|
| from sqlalchemy import DateTime, ForeignKey, JSON, String, UniqueConstraint, func |
| from sqlalchemy.orm import Mapped, mapped_column |
|
|
| from app.core.database import Base |
| from app.utils.ids import prefixed_id |
|
|
|
|
| class ClassSessionProgress(Base): |
| """Per-user, per-class tuition class progress (the 11-step guided class). |
| |
| One row per (user, class_session_id). The resumable class state is stored as |
| a JSON blob so the step shape can evolve freely. |
| """ |
|
|
| __tablename__ = "class_session_progress" |
| __table_args__ = ( |
| UniqueConstraint("user_id", "class_session_id", name="uq_class_session_user_session"), |
| ) |
|
|
| id: Mapped[str] = mapped_column( |
| String(40), |
| primary_key=True, |
| default=lambda: prefixed_id("cprog"), |
| ) |
| user_id: Mapped[str] = mapped_column( |
| String(40), |
| ForeignKey("users.id"), |
| index=True, |
| nullable=False, |
| ) |
| class_session_id: Mapped[str] = mapped_column(String(200), nullable=False) |
| data: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict, nullable=False) |
| created_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| server_default=func.now(), |
| nullable=False, |
| ) |
| updated_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| server_default=func.now(), |
| onupdate=func.now(), |
| nullable=False, |
| ) |
|
|