Skip to content

feat(data_export): add workflow support for data export #784#602

Merged
iwanghc merged 4 commits intomainfrom
dms/feat-784
Apr 24, 2026
Merged

feat(data_export): add workflow support for data export #784#602
iwanghc merged 4 commits intomainfrom
dms/feat-784

Conversation

@LordofAvernus
Copy link
Copy Markdown
Collaborator

@LordofAvernus LordofAvernus commented Apr 23, 2026

User description

Summary

  • Add AuditWorkflowAndAdvanceStep to WorkflowRepo for data export workflow audit operations
  • Add bounds check for CurrentWorkflowStepId in list endpoints to prevent index out of range
  • Show workflow creator as pending operator in wait_for_export status
  • Fix ProxyTarget version column size to 512

Related: https://github.com/actiontech/dms-ee/issues/784


Description

  • 新增 "AuditWorkflowAndAdvanceStep" 接口实现

  • 修改数据导出工作流中待操作人显示逻辑

  • 扩大 "ProxyTarget" 版本字段长度到 512

  • 优化事务处理与错误反馈


Diagram Walkthrough

flowchart LR
  A["\"WorkflowRepo接口更新\""] --> B["\"待操作人状态判断修改\""]
  B --> C["\"ProxyTarget版本字段扩展\""]
  A --> D["\"新增审批流程原子更新实现\""]
Loading

File Walkthrough

Relevant files
Enhancement
data_export_workflow.go
新增审批流程原子更新接口                                                                                         

internal/dms/biz/data_export_workflow.go

  • 添加 AuditWorkflowAndAdvanceStep 方法定义
+1/-0     
workflow.go
添加事务处理的审批更新实现                                                                                       

internal/dms/storage/workflow.go

  • 添加 AuditWorkflowAndAdvanceStep 方法实现
  • 封装事务内更新流程步骤状态与推进
+18/-0   
Bug fix
data_export_workflow.go
优化待操作人状态显示逻辑                                                                                         

internal/dms/service/data_export_workflow.go

  • 修改待操作人显示条件
  • 增加 wait_for_export 状态判断逻辑
+10/-2   
model.go
更新ProxyTarget版本字段长度                                                                           

internal/dms/storage/model/model.go

  • 将 ProxyTarget 版本字段长度由64改为512
+1/-1     

DEV-015: Add AuditWorkflowAndAdvanceStep method to the WorkflowRepo
interface and its storage implementation. This method atomically updates
the current step state and advances CurrentWorkflowStepId to the next
step within a transaction, providing the foundation for multi-step
approval in data export workflows.

refs actiontech/dms-ee#784

(cherry picked from commit 35fb0dae38f6da94d3ef6af78eb11d2e6b9ed235)
The version column (size:64) was too small for dev branch names
like "feat/784-data-export-workflow-template <40-char-hash>" (79+ chars),
causing auto-migration to fail with "Data truncated" error and
preventing DMS from starting.

(cherry picked from commit f1fd24ed15b5d2af88bdc6dca9e98922c42d08db)
When a data export workflow has no approval steps (CurrentWorkflowStepId=0,
WorkflowSteps=[]), the list and global list endpoints would panic with
"index out of range" when trying to access WorkflowSteps[CurrentWorkflowStepId-1].

Add bounds checks to prevent this panic, consistent with the webhook fix
in the previous commit.

(cherry picked from commit 0e8ba22932da83133602d7bdea8c126064d0f60e)
…rt status

When data export workflow enters wait_for_export or exporting status,
display the workflow creator as the current step assignee user in the
list endpoint, since the export executor is always the workflow creator.

(cherry picked from commit 06b2a1f3db3b44698ba3407d230df98c36453343)
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
添加 nil 检查

建议在使用 step 前先判断是否为 nil,以避免由于传入 nil 导致运行时 panic。这样可以确保在后续使用 step.Statestep.StepId
等属性时有有效值。

internal/dms/storage/workflow.go [288-304]

 func (d *WorkflowRepo) AuditWorkflowAndAdvanceStep(ctx context.Context, workflowRecordUid string, step *biz.WorkflowStep, nextStepId uint64, operateId, reason string) error {
+	if step == nil {
+		return fmt.Errorf("invalid step: step is nil")
+	}
 	return transaction(d.log, ctx, d.db, func(tx *gorm.DB) error {
 		// update current step state
 		operateTime := time.Now()
 		fields := map[string]interface{}{"operation_user_uid": operateId, "operate_at": operateTime, "reason": reason, "state": step.State}
 		if err := tx.WithContext(ctx).Model(&model.WorkflowStep{}).Where("step_id = ? and workflow_record_uid = ?", step.StepId, step.WorkflowRecordUid).Updates(fields).Error; err != nil {
 			return fmt.Errorf("failed to update current workflow step, err: %v", err)
 		}
 		// advance CurrentWorkflowStepId to next step
 		if err := tx.WithContext(ctx).Model(&model.WorkflowRecord{}).Where("uid = ?", workflowRecordUid).Update("current_workflow_step_id", nextStepId).Error; err != nil {
 			return fmt.Errorf("failed to advance workflow step, err: %v", err)
 		}
 		return nil
 	})
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly adds a nil check for step to prevent runtime panics and improve error handling, addressing a potential edge case. However, as this is a defensive programming addition and related to error checking, the impact is moderate.

Medium

@iwanghc iwanghc merged commit 10288ef into main Apr 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants