File size: 1,720 Bytes
d787a09 | 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 43 44 45 46 47 48 49 50 | """SQLAlchemy ORM models for saved progress."""
from __future__ import annotations
from datetime import datetime
from typing import List
from sqlalchemy import DateTime, ForeignKey, String, Text, UniqueConstraint
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
class Base(DeclarativeBase):
pass
class Matter(Base):
"""A saved roadmap session for one user's case (no PII required)."""
__tablename__ = "matters"
id: Mapped[int] = mapped_column(primary_key=True)
label: Mapped[str] = mapped_column(String(120), default="My Illinois divorce")
flow_id: Mapped[str] = mapped_column(String(64), default="il_divorce")
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
)
steps: Mapped[List["StepProgress"]] = relationship(
back_populates="matter",
cascade="all, delete-orphan",
)
class StepProgress(Base):
"""Per-step completion state + optional user note for a matter."""
__tablename__ = "step_progress"
__table_args__ = (UniqueConstraint("matter_id", "step_id", name="uq_matter_step"),)
id: Mapped[int] = mapped_column(primary_key=True)
matter_id: Mapped[int] = mapped_column(ForeignKey("matters.id"))
step_id: Mapped[str] = mapped_column(String(64))
done: Mapped[bool] = mapped_column(default=False)
note: Mapped[str] = mapped_column(Text, default="")
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
)
matter: Mapped["Matter"] = relationship(back_populates="steps")
|