"""Delivery log of the demo scheduler (#13): one row per delivered event, the unique key makes runs idempotent. Clinical DB, keyed by token only (guardrail #5). Created by `init_db` (`app.db.bootstrap`). """ from datetime import datetime from sqlalchemy import String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from app.db.clinical import TOKEN_LEN, BigId, ClinicalBase from app.db.types import TZDateTime class SchedulerEvent(ClinicalBase): __tablename__ = "scheduler_events" __table_args__ = (UniqueConstraint("token", "key", name="uq_scheduler_events_token_key"),) id: Mapped[int] = mapped_column(BigId, primary_key=True, autoincrement=True) token: Mapped[str] = mapped_column(String(TOKEN_LEN)) key: Mapped[str] = mapped_column(String(96)) # e.g. "dose:3:2026-10-06T08:00", "checkin:2026-10-06" kind: Mapped[str] = mapped_column(String(32)) # med_reminder | missed | daily_checkin | scale_due | evaluation due_at: Mapped[datetime] = mapped_column(TZDateTime) done_at: Mapped[datetime] = mapped_column(TZDateTime)