d25c8d371f
Restructure the persistence layer from horizontal "models/ + repositories/"
split into vertical entity-aligned directories. Each entity (thread_meta,
run, feedback) now owns its ORM model, abstract interface (where applicable),
and concrete implementations under a single directory with an aggregating
__init__.py for one-line imports.
Layout:
persistence/thread_meta/{base,model,sql,memory}.py
persistence/run/{model,sql}.py
persistence/feedback/{model,sql}.py
models/__init__.py is kept as a facade so Alembic autogenerate continues to
discover all ORM tables via Base.metadata. RunEventRow remains under
models/run_event.py because its storage implementation lives in
runtime/events/store/db.py and has no matching repository directory.
The repositories/ directory is removed entirely. All call sites in
gateway/deps.py and tests are updated to import from the new entity
packages, e.g.:
from deerflow.persistence.thread_meta import ThreadMetaRepository
from deerflow.persistence.run import RunRepository
from deerflow.persistence.feedback import FeedbackRepository
Full test suite passes (1690 passed, 14 skipped).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""ORM model for user feedback on runs."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import DateTime, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from deerflow.persistence.base import Base
|
|
|
|
|
|
class FeedbackRow(Base):
|
|
__tablename__ = "feedback"
|
|
|
|
feedback_id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
run_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
|
thread_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
|
owner_id: Mapped[str | None] = mapped_column(String(64), index=True)
|
|
message_id: Mapped[str | None] = mapped_column(String(64))
|
|
# message_id is an optional RunEventStore event identifier —
|
|
# allows feedback to target a specific message or the entire run
|
|
|
|
rating: Mapped[int] = mapped_column(nullable=False)
|
|
# +1 (thumbs-up) or -1 (thumbs-down)
|
|
|
|
comment: Mapped[str | None] = mapped_column(Text)
|
|
# Optional text feedback from the user
|
|
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))
|