Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: plan check run sample (#13333)
p0nyab2d6eca0361
diff --git a/backend/common/util.go b/backend/common/util.goindex f2a17cd627..8dd67da4b5 100644--- a/backend/common/util.go+++ b/backend/common/util.go@@ -34,6 +34,9 @@ const (MaximumAdvicePerStatus = 50MaximumLintExplainSize = 10+ // MinimumCompletedPlanCheckRun is the minimum number required to generate approval flow.+ MinimumCompletedPlanCheckRun = 5+// ExternalURLPlaceholder is the docs link to configure --external-url.ExternalURLPlaceholder = "https://www.bytebase.com/docs/get-started/install/external-url")diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.goindex e6d3263efc..d852a5cdf7 100644--- a/backend/runner/approval/runner.go+++ b/backend/runner/approval/runner.go@@ -357,8 +357,9 @@ func getDatabaseGeneralIssueRisk(ctx context.Context, s *store.Store, sheetManag}planCheckRuns, err := s.ListPlanCheckRuns(ctx, &store.FindPlanCheckRunMessage{- PlanUID: &plan.UID,- Type: &[]store.PlanCheckRunType{store.PlanCheckDatabaseStatementSummaryReport},+ PlanUID: &plan.UID,+ Type: &[]store.PlanCheckRunType{store.PlanCheckDatabaseStatementSummaryReport},+ LatestOnly: true,})if err != nil {return 0, store.RiskSourceUnknown, false, errors.Wrapf(err, "failed to list plan check runs for plan %v", plan.UID)@@ -373,10 +374,21 @@ func getDatabaseGeneralIssueRisk(ctx context.Context, s *store.Store, sheetManagInstanceUID: int(run.Config.InstanceUid),DatabaseName: run.Config.DatabaseName,}- oldValue, ok := latestPlanCheckRun[key]- if !ok || oldValue.UID < run.UID {- latestPlanCheckRun[key] = run+ latestPlanCheckRun[key] = run+ }++ // Get the max risk level of the same risk source.+ // risks is sorted by level DESC, so we just need to return the 1st matched risk.+ var maxRiskSourceRiskLevel int32+ for _, risk := range risks {+ if !risk.Active {+ continue}+ if risk.Source != riskSource {+ continue+ }+ maxRiskSourceRiskLevel = risk.Level+ break}// If any plan check run is skipped because of large SQL,@@ -384,27 +396,29 @@ func getDatabaseGeneralIssueRisk(ctx context.Context, s *store.Store, sheetManagfor _, run := range latestPlanCheckRun {for _, result := range run.Result.GetResults() {if result.GetCode() == common.SizeExceeded.Int32() {- // risks is sorted by level DESC, so we just need to return the 1st matched risk.- for _, risk := range risks {- if !risk.Active {- continue- }- if risk.Source != riskSource {- continue- }- return risk.Level, riskSource, true, nil- }- return 0, riskSource, true, nil+ return maxRiskSourceRiskLevel, riskSource, true, nil}}}+ var planCheckRunDone int// the latest plan check run is not done yet, return done=falsefor _, run := range latestPlanCheckRun {- if run.Status != store.PlanCheckRunStatusDone {- return 0, store.RiskSourceUnknown, false, nil+ if run.Status == store.PlanCheckRunStatusDone {+ planCheckRunDone++}}+ planCheckRunCount := len(latestPlanCheckRun)+ // We have less than 5 planCheckRuns in total.+ // We wait for all of them to finish.+ if planCheckRunCount < common.MinimumCompletedPlanCheckRun && planCheckRunCount != planCheckRunDone {+ return 0, store.RiskSourceUnknown, false, nil+ }+ // We have not less than 5 planCheckRuns in total.+ // We need at least 5 completed plan check run.+ if planCheckRunCount >= common.MinimumCompletedPlanCheckRun && planCheckRunDone < common.MinimumCompletedPlanCheckRun {+ return 0, store.RiskSourceUnknown, false, nil+ }pipelineCreate, err := apiv1.GetPipelineCreate(ctx, s, sheetManager, licenseService, dbFactory, plan.Config.Steps, issue.Project)if err != nil {@@ -543,7 +557,7 @@ func getDatabaseGeneralIssueRisk(ctx context.Context, s *store.Store, sheetManagif maxRiskLevel < risk {maxRiskLevel = risk}- if level, _ := convertRiskLevel(maxRiskLevel); level == storepb.IssuePayloadApproval_HIGH {+ if maxRiskLevel == maxRiskSourceRiskLevel {return maxRiskLevel, riskSource, true, nil}}