Skip to content

Commit

Permalink
Merge pull request #2427 from actiontech/fix-issue1532-3
Browse files Browse the repository at this point in the history
tasks/audits api add file_order_method param
  • Loading branch information
ColdWaterLW committed May 22, 2024
2 parents fa42026 + 49c7fdd commit 9337453
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
18 changes: 14 additions & 4 deletions sqle/api/controller/v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import (
var ErrTooManyDataSource = errors.New(errors.DataConflict, fmt.Errorf("the number of data sources must be less than %v", MaximumDataSourceNum))

type CreateAuditTaskReqV1 struct {
InstanceName string `json:"instance_name" form:"instance_name" example:"inst_1" valid:"required"`
InstanceSchema string `json:"instance_schema" form:"instance_schema" example:"db1"`
Sql string `json:"sql" form:"sql" example:"alter table tb1 drop columns c1"`
ExecMode string `json:"exec_mode" enums:"sql_file,sqls"`
InstanceName string `json:"instance_name" form:"instance_name" example:"inst_1" valid:"required"`
InstanceSchema string `json:"instance_schema" form:"instance_schema" example:"db1"`
Sql string `json:"sql" form:"sql" example:"alter table tb1 drop columns c1"`
ExecMode string `json:"exec_mode" form:"exec_mode" enums:"sql_file,sqls"`
FileOrderMethod string `json:"file_order_method" form:"file_order_method"`
}

type GetAuditTaskResV1 struct {
Expand Down Expand Up @@ -319,12 +320,21 @@ func CreateAndAuditTask(c echo.Context) error {
task.Instance = nil

task.ExecMode = req.ExecMode
task.FileOrderMethod = req.FileOrderMethod
taskGroup := model.TaskGroup{Tasks: []*model.Task{task}}
err = s.Save(&taskGroup)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if len(fileRecords) > 0 {
fileHeader, _, err := getFileHeaderFromContext(c)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if strings.HasSuffix(fileHeader.Filename, ZIPFileExtension) && req.FileOrderMethod != "" && task.ExecMode == model.ExecModeSqlFile {
sortAuditFiles(fileRecords, req.FileOrderMethod)
}

err = batchCreateFileRecords(s, fileRecords, task.ID)
if err != nil {
return controller.JSONBaseErrorReq(c, errors.New(errors.GenericError, fmt.Errorf("save sql file record failed: %v", err)))
Expand Down
3 changes: 3 additions & 0 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9002,6 +9002,9 @@ var doc = `{
"sqls"
]
},
"file_order_method": {
"type": "string"
},
"instance_name": {
"type": "string",
"example": "inst_1"
Expand Down
3 changes: 3 additions & 0 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8986,6 +8986,9 @@
"sqls"
]
},
"file_order_method": {
"type": "string"
},
"instance_name": {
"type": "string",
"example": "inst_1"
Expand Down
2 changes: 2 additions & 0 deletions sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ definitions:
- sql_file
- sqls
type: string
file_order_method:
type: string
instance_name:
example: inst_1
type: string
Expand Down

0 comments on commit 9337453

Please sign in to comment.