from sqlalchemy import BigInteger, ForeignKey, Integer, SmallInteger, String from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import BaseModel, SoftDeleteMixin class WorkflowDef(BaseModel, SoftDeleteMixin): __tablename__ = "bx_workflow_def" biz_type: Mapped[str] = mapped_column(String(32), nullable=False) wf_name: Mapped[str] = mapped_column(String(128), nullable=False) status: Mapped[int] = mapped_column(SmallInteger, nullable=False, default=1, server_default="1") remark: Mapped[str | None] = mapped_column(String(512)) nodes: Mapped[list["WorkflowNode"]] = relationship(back_populates="workflow_def") class WorkflowNode(BaseModel): __tablename__ = "bx_workflow_node" wf_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("bx_workflow_def.id"), nullable=False) node_name: Mapped[str] = mapped_column(String(128), nullable=False) node_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default="0") approver_id: Mapped[int | None] = mapped_column(BigInteger) approver_name: Mapped[str | None] = mapped_column(String(64)) workflow_def: Mapped["WorkflowDef"] = relationship(back_populates="nodes")