- 业务 ORM 数据支持 MySQL 后端(asyncmy),新增 PortableJSON/
BeijingDateTime 可移植列类型、迁移脚本与切库脚本
- 修复 GET /api/scheduled-tasks/runs/{id} 的 _load_run 无限递归
(误调用自身,应委托 service.get_run)导致的 RecursionError 500
- 定时任务名按用户唯一:create/update/admin_update 主动校验,
冲突抛 DuplicateTaskNameError,路由转 409 而非裸 IntegrityError 500
- 补充回归测试 test_scheduled_task_run_lookup / _name_uniqueness
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
"""ORM model for run events."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import Index, String, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from deerflow.persistence.base import Base
|
|
from deerflow.persistence.types import BeijingDateTime, PortableJSON
|
|
|
|
|
|
class RunEventRow(Base):
|
|
__tablename__ = "run_events"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
thread_id: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
run_id: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
# Owner of the conversation this event belongs to. Nullable for data
|
|
# created before auth was introduced; populated by auth middleware on
|
|
# new writes and by the boot-time orphan migration on existing rows.
|
|
user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
|
event_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
category: Mapped[str] = mapped_column(String(16), nullable=False)
|
|
# "message" | "trace" | "lifecycle"
|
|
content: Mapped[str] = mapped_column(Text, default="")
|
|
event_metadata: Mapped[dict] = mapped_column(PortableJSON(), default=dict)
|
|
seq: Mapped[int] = mapped_column(nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), default=lambda: datetime.now(UTC))
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("thread_id", "seq", name="uq_events_thread_seq"),
|
|
Index("ix_events_thread_cat_seq", "thread_id", "category", "seq"),
|
|
Index("ix_events_run", "thread_id", "run_id", "seq"),
|
|
)
|