from __future__ import annotations import uuid from datetime import datetime from sqlalchemy import ( DateTime, ForeignKey, String, Text, func, text, ) from sqlalchemy.dialects.postgresql import JSONB, UUID from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database.database import Base class WorkflowCheckpoint(Base): """ Stores workflow progress so execution can resume after crashes or interruptions. """ __tablename__ = "workflow_checkpoints" id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, ) workflow_run_id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), ForeignKey("workflow_runs.id", ondelete="CASCADE"), nullable=False, index=True, ) agent_name: Mapped[str] = mapped_column( String(100), nullable=False, ) state: Mapped[dict] = mapped_column( JSONB, nullable=False, default=dict, server_default=text("'{}'::jsonb"), ) message: Mapped[str | None] = mapped_column( Text, nullable=True, ) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now(), ) # ------------------------------------------------------------------ # Relationships # ------------------------------------------------------------------ workflow_run: Mapped["WorkflowRun"] = relationship( back_populates="checkpoints", ) def __repr__(self) -> str: return ( f"" )