state-hub/api/models/memo_notification.py

38 lines
1.4 KiB
Python
Raw Permalink Normal View History

import uuid
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, String, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column
from api.models.base import Base
class MemoNotificationReceipt(Base):
"""Durable receipt for one informed-decision delivery id.
The delivery id is the sender's stable idempotency key. The body is only
memo id, question, class, and submitter. Rows are retained, not expired.
"""
__tablename__ = "memo_notification_receipts"
delivery_id: Mapped[str] = mapped_column(String(128), primary_key=True)
body_digest: Mapped[str] = mapped_column(String(64), nullable=False)
memo_id: Mapped[str] = mapped_column(String(63), nullable=False)
question: Mapped[str] = mapped_column(String(400), nullable=False)
memo_class: Mapped[str] = mapped_column(String(63), nullable=False)
submitter: Mapped[str] = mapped_column(String(63), nullable=False)
message_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
ForeignKey("agent_messages.id", ondelete="RESTRICT"),
nullable=False,
index=True,
)
authoritative_review: Mapped[str] = mapped_column(
String(40), nullable=False, default="signed-in-overview"
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)