Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql version manage #2676

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func CreateWorkflowV2(c echo.Context) error {
}
}

err = s.CreateWorkflowV2(req.Subject, workflowId, req.Desc, user, tasks, stepTemplates, model.ProjectUID(projectUid), req.SqlVersionID, nil, nil, func(tasks []*model.Task) (auditWorkflowUsers, canExecUser [][]*model.User) {
err = s.CreateWorkflowV2(req.Subject, workflowId, req.Desc, user, tasks, stepTemplates, model.ProjectUID(projectUid), req.SqlVersionID, func(tasks []*model.Task) (auditWorkflowUsers, canExecUser [][]*model.User) {
auditWorkflowUsers = make([][]*model.User, len(tasks))
executorWorkflowUsers := make([][]*model.User, len(tasks))
for i, task := range tasks {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ func GetWorkflowV2(c echo.Context) error {
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
sqlVersion, err := s.GetSQLVersionByWorkflowId(workflow.WorkflowId)
sqlVersion, _, err := s.GetSQLVersionByWorkflowId(workflow.WorkflowId)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
Expand All @@ -1240,11 +1240,14 @@ func convertWorkflowToRes(ctx context.Context, workflow *model.Workflow, sqlVers
CreateTime: &workflow.CreatedAt,
AssociatedStageWorkflows: convertAssociatedWorkflowToRes(associatedWorkflows),
}
sqlVersionRes := &SqlVersion{
SqlVersionId: sqlVersion.ID,
SqlVersionName: sqlVersion.Version,
if sqlVersion != nil {
sqlVersionRes := &SqlVersion{
SqlVersionId: sqlVersion.ID,
SqlVersionName: sqlVersion.Version,
}
workflowRes.SqlVersion = sqlVersionRes

}
workflowRes.SqlVersion = sqlVersionRes
// convert workflow record
workflowRecordRes := convertWorkflowRecordToRes(ctx, workflow, workflow.Record)

Expand Down
4 changes: 2 additions & 2 deletions sqle/model/sql_version_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func (s *Storage) GetAssociatedStageWorkflows(workflowId string) ([]*AssociatedS
return nil, nil
}

func (s *Storage) GetSQLVersionByWorkflowId(workflowId string) (*SqlVersion, error) {
return &SqlVersion{}, nil
func (s *Storage) GetSQLVersionByWorkflowId(workflowId string) (*SqlVersion, bool, error) {
return &SqlVersion{}, false, nil
}
38 changes: 12 additions & 26 deletions sqle/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ func (w *Workflow) GetNeedSendOATaskIds(entry *logrus.Entry) ([]uint, error) {
return taskIds, nil
}

func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, tasks []*Task, stepTemplates []*WorkflowStepTemplate, projectId ProjectUID, sqlVersionId, versionStageId *uint, workflowStageSequence *int, getOpExecUser func([]*Task) (canAuditUsers [][]*User, canExecUsers [][]*User)) error {
func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, tasks []*Task, stepTemplates []*WorkflowStepTemplate, projectId ProjectUID,
sqlVersionId *uint, getOpExecUser func([]*Task) (canAuditUsers [][]*User, canExecUsers [][]*User)) error {
if len(tasks) <= 0 {
return errors.New(errors.DataConflict, fmt.Errorf("there is no task for creating workflow"))
}
Expand Down Expand Up @@ -594,42 +595,27 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User,
}
}
}

// 在SQL版本的第一阶段建立与工单的关联
if sqlVersionId != nil {
stage := &SqlVersionStage{}
if versionStageId == nil {
// get the first stage
err = tx.Model(&SqlVersionStage{}).
Preload("WorkflowVersionStage").
Preload("SqlVersionStagesDependency").
Where("sql_version_id = ?", sqlVersionId).
Order("stage_sequence ASC").First(stage).Error
} else {
// get specific stage
err = tx.Model(&SqlVersionStage{}).
Preload("WorkflowVersionStage").
Preload("SqlVersionStagesDependency").
Where("sql_version_id = ? AND id = ?", sqlVersionId, versionStageId).
First(stage).Error
}
// 获取版本的第一个阶段
err := tx.Model(&SqlVersionStage{}).
Preload("WorkflowVersionStage").
Preload("SqlVersionStagesDependency").
Where("sql_version_id = ?", sqlVersionId).
Order("stage_sequence ASC").First(stage).Error
if err != nil {
tx.Rollback()
return errors.New(errors.ConnectStorageError, err)
}
// associate sql version with workflow
// 建立版本阶段与工单的关联
workflowVersionStageRelation := &WorkflowVersionStage{
WorkflowID: workflowId,
SqlVersionID: *sqlVersionId,
SqlVersionStageID: stage.ID,
WorkflowReleaseStatus: stage.InitialStatusOfWorkflow(),
}

if workflowStageSequence != nil {
// 当在版本中发布工单时,工单发布到下一阶段所在的占位由当前阶段决定
workflowVersionStageRelation.WorkflowSequence = *workflowStageSequence
} else {
// 当在版本中新建工单时,该工单的顺序为该阶段的最后一条工单
workflowVersionStageRelation.WorkflowSequence = len(stage.WorkflowVersionStage) + 1
// 在版本中新建工单时,该工单的顺序为该阶段的最后一条工单
WorkflowSequence: len(stage.WorkflowVersionStage) + 1,
}
err = tx.Create(workflowVersionStageRelation).Error
if err != nil {
Expand Down
Loading