2026-01-19 00:09:36 +08:00
|
|
|
"""
|
|
|
|
|
工作流模型
|
|
|
|
|
"""
|
2026-06-29 01:17:21 +08:00
|
|
|
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, ForeignKey, Index, func
|
2026-01-19 00:09:36 +08:00
|
|
|
from sqlalchemy.dialects.mysql import CHAR
|
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
from app.core.database import Base
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Workflow(Base):
|
|
|
|
|
"""工作流表"""
|
|
|
|
|
__tablename__ = "workflows"
|
|
|
|
|
|
|
|
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="工作流ID")
|
|
|
|
|
name = Column(String(100), nullable=False, comment="工作流名称")
|
|
|
|
|
description = Column(Text, comment="描述")
|
|
|
|
|
nodes = Column(JSON, nullable=False, comment="节点配置")
|
|
|
|
|
edges = Column(JSON, nullable=False, comment="边配置")
|
|
|
|
|
version = Column(Integer, default=1, comment="版本号")
|
|
|
|
|
status = Column(String(20), default="draft", comment="状态: draft/published/running/stopped")
|
|
|
|
|
user_id = Column(CHAR(36), ForeignKey("users.id"), comment="创建者ID")
|
2026-06-29 01:17:21 +08:00
|
|
|
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, comment="所属工作区ID")
|
2026-01-19 00:09:36 +08:00
|
|
|
created_at = Column(DateTime, default=func.now(), comment="创建时间")
|
|
|
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
|
|
|
|
|
|
|
|
|
|
# 关系
|
|
|
|
|
user = relationship("User", backref="workflows")
|
|
|
|
|
|
2026-06-29 01:17:21 +08:00
|
|
|
__table_args__ = (
|
|
|
|
|
Index("ix_workflows_workspace", "workspace_id"),
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-19 00:09:36 +08:00
|
|
|
def __repr__(self):
|
|
|
|
|
return f"<Workflow(id={self.id}, name={self.name})>"
|