DocWeave / backend /app /models /workflow_checkpoint.py
shak3008's picture
feat: initialize DocWeave backend foundation with Neon, Alembic, ORM models, repositories, and workspace architecture
1d92db8
Raw
History Blame Contribute Delete
1.74 kB
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"<WorkflowCheckpoint("
f"agent='{self.agent_name}')>"
)