Implement complete workflow engine with BPMN subset support: Backend (erp-workflow crate): - Token-driven execution engine with exclusive/parallel gateway support - BPMN parser with flow graph validation - Expression evaluator for conditional branching - Process definition CRUD with draft/publish lifecycle - Process instance management (start, suspend, terminate) - Task service (pending, complete, delegate) - PostgreSQL advisory locks for concurrent safety - 5 database tables: process_definitions, process_instances, tokens, tasks, process_variables - 13 API endpoints with RBAC protection - Timeout checker framework (placeholder) Frontend: - Workflow page with 4 tabs (definitions, pending, completed, monitor) - React Flow visual process designer (@xyflow/react) - Process viewer with active node highlighting - 3 API client modules for workflow endpoints - Sidebar menu integration
125 lines
4.1 KiB
Rust
125 lines
4.1 KiB
Rust
use sea_orm_migration::prelude::*;
|
|
|
|
#[derive(DeriveMigrationName)]
|
|
pub struct Migration;
|
|
|
|
#[async_trait::async_trait]
|
|
impl MigrationTrait for Migration {
|
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.create_table(
|
|
Table::create()
|
|
.table(ProcessInstances::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::Id)
|
|
.uuid()
|
|
.not_null()
|
|
.primary_key(),
|
|
)
|
|
.col(ColumnDef::new(ProcessInstances::TenantId).uuid().not_null())
|
|
.col(ColumnDef::new(ProcessInstances::DefinitionId).uuid().not_null())
|
|
.col(ColumnDef::new(ProcessInstances::BusinessKey).string().null())
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::Status)
|
|
.string()
|
|
.not_null()
|
|
.default("running"),
|
|
)
|
|
.col(ColumnDef::new(ProcessInstances::StartedBy).uuid().not_null())
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::StartedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::CompletedAt)
|
|
.timestamp_with_time_zone()
|
|
.null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::CreatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::UpdatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(ColumnDef::new(ProcessInstances::CreatedBy).uuid().not_null())
|
|
.col(ColumnDef::new(ProcessInstances::UpdatedBy).uuid().not_null())
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::DeletedAt)
|
|
.timestamp_with_time_zone()
|
|
.null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(ProcessInstances::Version)
|
|
.integer()
|
|
.not_null()
|
|
.default(1),
|
|
)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_index(
|
|
Index::create()
|
|
.name("idx_instances_tenant_status")
|
|
.table(ProcessInstances::Table)
|
|
.col(ProcessInstances::TenantId)
|
|
.col(ProcessInstances::Status)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_foreign_key(
|
|
ForeignKey::create()
|
|
.name("fk_instances_definition")
|
|
.from(ProcessInstances::Table, ProcessInstances::DefinitionId)
|
|
.to(ProcessDefinitions::Table, ProcessDefinitions::Id)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(ProcessInstances::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum ProcessInstances {
|
|
Table,
|
|
Id,
|
|
TenantId,
|
|
DefinitionId,
|
|
BusinessKey,
|
|
Status,
|
|
StartedBy,
|
|
StartedAt,
|
|
CompletedAt,
|
|
CreatedAt,
|
|
UpdatedAt,
|
|
CreatedBy,
|
|
UpdatedBy,
|
|
DeletedAt,
|
|
Version,
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum ProcessDefinitions {
|
|
Table,
|
|
Id,
|
|
}
|