Spaces:
Sleeping

studiq-backend / app /models /progress.py
StudIQ Deploy Bot
Deploy from GitHub cd855d878578a00bb146bd348ed765aa0921cf03
7ae37d5
Raw History Blame Contribute Delete
1.49 kB
"""UserProgress model — tracks per-topic study progress for each student."""
import uuid
from datetime import datetime
from typing import Optional
from sqlalchemy import ForeignKey, Index, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
from app.models.base import Base
class UserProgress(Base):
"""Tracks a student's progress on individual syllabus topics."""
__tablename__ = "user_progress"
__table_args__ = (
UniqueConstraint("user_id", "topic_id", name="uq_user_topic"),
Index("ix_user_progress_user_subject", "user_id", "subject_code"),
)
id: Mapped[uuid.UUID] = mapped_column(
primary_key=True, default=uuid.uuid4
)
user_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
topic_id: Mapped[str] = mapped_column(String(255), nullable=False)
subject_code: Mapped[Optional[str]] = mapped_column(
String(255), nullable=True
)
status: Mapped[str] = mapped_column(
String(20), default="not_started"
) # not_started / in_progress / completed
strength_score: Mapped[int] = mapped_column(Integer, default=0)
time_spent_minutes: Mapped[int] = mapped_column(Integer, default=0)
last_studied_at: Mapped[Optional[datetime]] = mapped_column(nullable=True)
created_at: Mapped[datetime] = mapped_column(server_default=func.now())