Skip to content

Commit

Permalink
Merge pull request #2755 from actiontech/1956mvp1-1
Browse files Browse the repository at this point in the history
feat: enable backup when audit
  • Loading branch information
taolx0 authored Nov 14, 2024
2 parents 938f11a + 163b4fc commit dffab08
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
28 changes: 27 additions & 1 deletion sqle/api/controller/v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func convertTaskToRes(task *model.Task) *AuditTaskResV1 {
ExecStartTime: task.ExecStartAt,
ExecEndTime: task.ExecEndAt,
ExecMode: task.ExecMode,
EnableBackup: task.EnableBackup,
FileOrderMethod: task.FileOrderMethod,
AuditFiles: convertToAuditFileResp(task.AuditFiles),
}
Expand Down Expand Up @@ -346,6 +347,18 @@ func CreateAndAuditTask(c echo.Context) error {

task.ExecMode = req.ExecMode
task.FileOrderMethod = req.FileOrderMethod
if req.EnableBackup {
backupService := server.BackupService{}
err = backupService.CheckBackupConflictWithExecMode(req.EnableBackup, req.ExecMode)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
err = backupService.CheckIsDbTypeSupportEnableBackup(task.DBType)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
task.EnableBackup = req.EnableBackup
}

err = convertSQLSourceEncodingFromTask(task)
if err != nil {
Expand Down Expand Up @@ -967,7 +980,7 @@ type AuditTaskGroupResV1 struct {
// @Param input_zip_file formData file false "input ZIP file"
// @Success 200 {object} v1.AuditTaskGroupResV1
// @router /v1/task_groups/audit [post]
func AuditTaskGroupV1(c echo.Context) error {
func AuditTaskGroupV1(c echo.Context) error {
// TODO 单数据源审核,以及多数据源相同SQL模式审核,增加备份配置
req := new(AuditTaskGroupReqV1)
if err := controller.BindAndValidateReq(c, req); err != nil {
Expand Down Expand Up @@ -1033,6 +1046,18 @@ func AuditTaskGroupV1(c echo.Context) error {

for _, task := range tasks {
task.SQLSource = sqls.SourceType
if req.EnableBackup {
backupService := server.BackupService{}
err = backupService.CheckBackupConflictWithExecMode(req.EnableBackup, task.ExecMode)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
err = backupService.CheckIsDbTypeSupportEnableBackup(task.DBType)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
task.EnableBackup = req.EnableBackup
}
err := addSQLsFromFileToTasks(sqls, task, plugin)
if err != nil {
return controller.JSONBaseErrorReq(c, errors.New(errors.GenericError, fmt.Errorf("add sqls from file to task failed: %v", err)))
Expand Down Expand Up @@ -1087,6 +1112,7 @@ func AuditTaskGroupV1(c echo.Context) error {
Score: task.Score,
PassRate: task.PassRate,
Status: task.Status,
EnableBackup: task.EnableBackup,
SQLSource: task.SQLSource,
ExecStartTime: task.ExecStartAt,
ExecEndTime: task.ExecEndAt,
Expand Down
1 change: 1 addition & 0 deletions sqle/model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Task struct {
ExecStartAt *time.Time
ExecEndAt *time.Time
ExecMode string `json:"exec_mode" gorm:"default:'sqls';type:varchar(255)" example:"sqls"`
EnableBackup bool `gorm:"column:enable_backup"`
FileOrderMethod string `json:"file_order_method" gorm:"column:file_order_method;type:varchar(255)"`
Instance *Instance `json:"-" gorm:"-"`
ExecuteSQLs []*ExecuteSQL `json:"-" gorm:"foreignkey:TaskId"`
Expand Down
14 changes: 14 additions & 0 deletions sqle/server/backup_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !enterprise
// +build !enterprise

package server

type BackupService struct{}

func (BackupService) CheckBackupConflictWithExecMode(EnableBackup bool, ExecMode string) error {
return nil
}

func (BackupService) CheckIsDbTypeSupportEnableBackup(dbType string) error {
return nil
}

0 comments on commit dffab08

Please sign in to comment.