"""ORM model for exact-match, administrator-managed fixed questions.""" from __future__ import annotations from datetime import UTC, datetime from sqlalchemy import Boolean, Integer, String, Text, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from deerflow.persistence.base import Base from deerflow.persistence.types import BeijingDateTime, PortableLongText class FixedQuestionRow(Base): """One globally shared question/answer pair. ``question_hash`` provides a portable indexed lookup for questions stored in ``Text``. The repository always compares the original question as well, so a theoretical SHA-256 collision cannot cause a false match. """ __tablename__ = "fixed_questions" __table_args__ = (UniqueConstraint("question_hash", name="uq_fixed_questions_question_hash"),) id: Mapped[str] = mapped_column(String(64), primary_key=True) question: Mapped[str] = mapped_column(Text, nullable=False) question_hash: Mapped[str] = mapped_column(String(64), nullable=False, index=True) answer: Mapped[str] = mapped_column(PortableLongText, nullable=False) enabled: Mapped[bool] = mapped_column(Boolean, default=True, server_default="1") tokens_per_second: Mapped[int] = mapped_column( Integer, default=100, server_default="100", ) sort_order: Mapped[int] = mapped_column(Integer, default=0, server_default="0") updated_by: Mapped[str | None] = mapped_column(String(64), nullable=True) updated_at: Mapped[datetime] = mapped_column( BeijingDateTime(), default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC), )