Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: approval runner, accept report result if the code is OK (#5245)
p0nyf9e2eeabd3cb
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.goindex 74fa35facb..477b3386c1 100644--- a/backend/runner/approval/runner.go+++ b/backend/runner/approval/runner.go@@ -15,6 +15,7 @@ import ("go.uber.org/zap""google.golang.org/protobuf/encoding/protojson"+ "github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/component/dbfactory"api "github.com/bytebase/bytebase/backend/legacyapi"@@ -354,13 +355,17 @@ func getTaskRiskLevel(ctx context.Context, s *store.Store, issue *store.IssueMesif len(affectedRowsReportResult) > 0 {for i := range affectedRowsReportResult {args := args- affectedRows, err := strconv.ParseInt(affectedRowsReportResult[i].Content, 10, 64)- if err != nil {- log.Warn("failed to convert affectedRows to int64, will use 0 as the value of affected_rows", zap.Error(err))- } else {- args["affected_rows"] = affectedRows+ if affectedRowsReportResult[i].Code == common.Ok.Int() {+ affectedRows, err := strconv.ParseInt(affectedRowsReportResult[i].Content, 10, 64)+ if err != nil {+ log.Warn("failed to convert affectedRows to int64, will use 0 as the value of affected_rows", zap.Error(err))+ } else {+ args["affected_rows"] = affectedRows+ }+ }+ if statementTypeReportResult[i].Code == common.Ok.Int() {+ args["sql_type"] = statementTypeReportResult[i].Content}- args["sql_type"] = statementTypeReportResult[i].Contentres, _, err := prg.Eval(args)if err != nil {diff --git a/backend/runner/taskcheck/statement_affected_rows_report_executor.go b/backend/runner/taskcheck/statement_affected_rows_report_executor.goindex 255a2a95ef..f612dc22b2 100644--- a/backend/runner/taskcheck/statement_affected_rows_report_executor.go+++ b/backend/runner/taskcheck/statement_affected_rows_report_executor.go@@ -39,18 +39,16 @@ type StatementAffectedRowsReportExecutor struct {// Run will run the task check statement affected rows report executor once.func (s *StatementAffectedRowsReportExecutor) Run(ctx context.Context, taskCheckRun *store.TaskCheckRunMessage, task *store.TaskMessage) ([]api.TaskCheckResult, error) {- switch task.Type {- case api.TaskDatabaseSchemaUpdate:- case api.TaskDatabaseSchemaUpdateSDL:- case api.TaskDatabaseSchemaUpdateGhostSync:- case api.TaskDatabaseDataUpdate:- default:+ if !api.IsTaskCheckReportNeededForTaskType(task.Type) {return nil, nil}payload := &api.TaskCheckDatabaseStatementAffectedRowsReportPayload{}if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {return nil, err}+ if !api.IsTaskCheckReportSupported(payload.DbType) {+ return nil, nil+ }instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})if err != nil {return nil, errdiff --git a/backend/runner/taskcheck/statement_type_report_executor.go b/backend/runner/taskcheck/statement_type_report_executor.goindex 2a273d1d27..580118d923 100644--- a/backend/runner/taskcheck/statement_type_report_executor.go+++ b/backend/runner/taskcheck/statement_type_report_executor.go@@ -3,10 +3,10 @@ package taskcheckimport ("context""encoding/json"- "errors"tidbparser "github.com/pingcap/tidb/parser"tidbast "github.com/pingcap/tidb/parser/ast"+ "github.com/pkg/errors""github.com/bytebase/bytebase/backend/common"api "github.com/bytebase/bytebase/backend/legacyapi"@@ -30,11 +30,17 @@ type StatementTypeReportExecutor struct {}// Run will run the task check statement type report executor once.-func (*StatementTypeReportExecutor) Run(_ context.Context, taskCheckRun *store.TaskCheckRunMessage, _ *store.TaskMessage) ([]api.TaskCheckResult, error) {+func (*StatementTypeReportExecutor) Run(_ context.Context, taskCheckRun *store.TaskCheckRunMessage, task *store.TaskMessage) ([]api.TaskCheckResult, error) {+ if !api.IsTaskCheckReportNeededForTaskType(task.Type) {+ return nil, nil+ }payload := &api.TaskCheckDatabaseStatementTypeReportPayload{}if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {return nil, err}+ if !api.IsTaskCheckReportSupported(payload.DbType) {+ return nil, nil+ }switch payload.DbType {case db.Postgres:return reportStatementTypeForPostgres(payload.Statement)