Spaces:
Build error
Build error
File size: 3,094 Bytes
71b4454 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from sqlalchemy import Column, Integer, String, DateTime, Text, JSON, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from datetime import datetime
Base = declarative_base()
class Workflow(Base):
__tablename__ = "workflows"
id = Column(Integer, primary_key=True)
workflow_id = Column(String(64), unique=True, nullable=False)
name = Column(String(128), nullable=False)
definition = Column(JSON, nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
version = Column(Integer, default=1)
executions = relationship("WorkflowExecution", back_populates="workflow")
steps = relationship("WorkflowStep", back_populates="workflow") # <-- added
class WorkflowStep(Base):
__tablename__ = "workflow_steps"
id = Column(Integer, primary_key=True)
step_id = Column(String(64), unique=True, nullable=False)
workflow_id = Column(Integer, ForeignKey("workflows.id"))
name = Column(String(128), nullable=False)
step_type = Column(String(32), nullable=False)
config = Column(JSON, nullable=False)
order = Column(Integer, default=0)
workflow = relationship("Workflow", back_populates="steps")
class WorkflowExecution(Base):
__tablename__ = "workflow_executions"
id = Column(Integer, primary_key=True)
execution_id = Column(String(64), unique=True, nullable=False)
workflow_id = Column(Integer, ForeignKey("workflows.id"))
status = Column(String(32), default="pending")
started_at = Column(DateTime, nullable=True)
completed_at = Column(DateTime, nullable=True)
current_step_index = Column(Integer, default=0)
context = Column(JSON, default={})
error = Column(Text, nullable=True)
workflow = relationship("Workflow", back_populates="executions")
step_results = relationship("StepResult", back_populates="execution")
approvals = relationship("ApprovalRequest", back_populates="execution")
class StepResult(Base):
__tablename__ = "step_results"
id = Column(Integer, primary_key=True)
execution_id = Column(Integer, ForeignKey("workflow_executions.id"))
step_id = Column(String(64), nullable=False)
status = Column(String(32), default="pending")
result = Column(JSON, nullable=True)
error = Column(Text, nullable=True)
started_at = Column(DateTime, nullable=True)
completed_at = Column(DateTime, nullable=True)
execution = relationship("WorkflowExecution", back_populates="step_results")
class ApprovalRequest(Base):
__tablename__ = "approval_requests"
id = Column(Integer, primary_key=True)
approval_id = Column(String(64), unique=True, nullable=False)
execution_id = Column(Integer, ForeignKey("workflow_executions.id"))
step_id = Column(String(64), nullable=False)
status = Column(String(32), default="pending")
requested_at = Column(DateTime, default=datetime.utcnow)
responded_at = Column(DateTime, nullable=True)
comment = Column(Text, nullable=True)
execution = relationship("WorkflowExecution", back_populates="approvals")
|