from datetime import datetime from core_db import AuditMixin, Base, EntityMixin, VersionMixin from sqlalchemy import DateTime, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column class WorkflowRun(EntityMixin, AuditMixin, VersionMixin, Base): __tablename__ = "workflow_run" app_id: Mapped[str] = mapped_column(String(36), index=True) app_version_id: Mapped[str] = mapped_column(String(36)) workflow_id: Mapped[str] = mapped_column(String(36)) workflow_version_id: Mapped[str] = mapped_column(String(36)) session_id: Mapped[str | None] = mapped_column(String(36), nullable=True, index=True) parent_run_id: Mapped[str | None] = mapped_column(String(36), nullable=True) root_run_id: Mapped[str | None] = mapped_column(String(36), nullable=True, index=True) run_type: Mapped[str] = mapped_column(String(32), default="main") status: Mapped[str] = mapped_column(String(32), default="pending", index=True) trigger_type: Mapped[str] = mapped_column(String(32), default="user") priority: Mapped[int] = mapped_column(Integer, default=0) current_node_count: Mapped[int] = mapped_column(Integer, default=0) started_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) finished_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) error_code: Mapped[str | None] = mapped_column(String(64), nullable=True) error_message: Mapped[str | None] = mapped_column(Text, nullable=True)