Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(approval): remove legacy plan check rerun (#20635)

p0nyd54f3e4db933
diff --git a/backend/api/v1/issue_hook.go b/backend/api/v1/issue_hook.go
index 53247037eb..bf64ea7fa0 100644
--- a/backend/api/v1/issue_hook.go
+++ b/backend/api/v1/issue_hook.go
@@ -49,7 +49,7 @@ func postCreateIssue(
storepb.Issue_ROLE_GRANT,
storepb.Issue_DATABASE_EXPORT:
- if err := approval.FindAndApplyApprovalTemplate(ctx, stores, b, webhookManager, licenseService, issue); err != nil {
+ if err := approval.FindAndApplyApprovalTemplate(ctx, stores, webhookManager, licenseService, issue); err != nil {
slog.Error("failed to find approval template",
slog.String("project", issue.ProjectID), slog.Int64("issue_uid", issue.UID),
slog.String("issue_title", issue.Title),
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 79a3b41c30..038c320e9f 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -889,7 +889,7 @@ func (s *IssueService) RetryIssueApproval(ctx context.Context, req *connect.Requ
return connect.NewResponse(issueV1), nil
}
- if err := approval.FindAndApplyApprovalTemplate(ctx, s.store, s.bus, s.webhookManager, s.licenseService, issue); err != nil {
+ if err := approval.FindAndApplyApprovalTemplate(ctx, s.store, s.webhookManager, s.licenseService, issue); err != nil {
// Surface the underlying cause (e.g. CEL error in the workspace
// approval rule) so the operator can fix it.
return nil, connect.NewError(connect.CodeFailedPrecondition, errors.Wrap(err, "approval finding still failing"))
diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.go
index aa1795492b..2dd5b6e4ea 100644
--- a/backend/api/v1/plan_service.go
+++ b/backend/api/v1/plan_service.go
@@ -372,7 +372,7 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *connect.Request[v
// which will trigger approval finding on completion
// DATABASE_EXPORT: Re-run approval finding synchronously (no plan checks for export data)
if updatedIssue.Type == storepb.Issue_DATABASE_EXPORT {
- if err := approval.FindAndApplyApprovalTemplate(ctx, s.store, s.bus, s.webhookManager, s.licenseService, updatedIssue); err != nil {
+ if err := approval.FindAndApplyApprovalTemplate(ctx, s.store, s.webhookManager, s.licenseService, updatedIssue); err != nil {
slog.Error("failed to find approval template after plan update",
slog.String("project", updatedIssue.ProjectID), slog.Int64("issue_uid", updatedIssue.UID),
slog.String("issue_title", updatedIssue.Title),
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index a72a1ae886..da730a9c97 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -66,7 +66,7 @@ func (r *Runner) Run(ctx context.Context, wg *sync.WaitGroup) {
// FindAndApplyApprovalTemplate finds and applies the approval template for an issue.
// This is a utility function that can be called synchronously (from issue creation)
// or asynchronously (from the event handler).
-func FindAndApplyApprovalTemplate(ctx context.Context, stores *store.Store, b *bus.Bus, webhookManager *webhook.Manager, licenseService *enterprise.LicenseService, issue *store.IssueMessage) error {
+func FindAndApplyApprovalTemplate(ctx context.Context, stores *store.Store, webhookManager *webhook.Manager, licenseService *enterprise.LicenseService, issue *store.IssueMessage) error {
project, err := stores.GetProjectByResourceID(ctx, issue.ProjectID)
if err != nil {
return errors.Wrap(err, "failed to get project")
@@ -80,7 +80,7 @@ func FindAndApplyApprovalTemplate(ctx context.Context, stores *store.Store, b *b
}
// Find approval template - errors are logged, not persisted
- err = findApprovalTemplateForIssue(ctx, stores, b, webhookManager, licenseService, issue, approvalSetting)
+ err = findApprovalTemplateForIssue(ctx, stores, webhookManager, licenseService, issue, approvalSetting)
if err != nil {
return errors.Wrap(err, "failed to find approval template")
}
@@ -115,7 +115,7 @@ func (r *Runner) processIssue(ctx context.Context, ref bus.IssueRef) {
return
}
- if err := findApprovalTemplateForIssue(ctx, r.store, r.bus, r.webhookManager, r.licenseService, issue, approvalSetting); err != nil {
+ if err := findApprovalTemplateForIssue(ctx, r.store, r.webhookManager, r.licenseService, issue, approvalSetting); err != nil {
slog.Error("failed to find approval template",
slog.String("project", ref.ProjectID), slog.Int64("issue_uid", ref.UID),
slog.String("issue_title", issue.Title),
@@ -151,7 +151,7 @@ func (r *Runner) processIssue(ctx context.Context, ref bus.IssueRef) {
}
}
-func findApprovalTemplateForIssue(ctx context.Context, stores *store.Store, b *bus.Bus, webhookManager *webhook.Manager, licenseService *enterprise.LicenseService, issue *store.IssueMessage, approvalSetting *storepb.WorkspaceApprovalSetting) error {
+func findApprovalTemplateForIssue(ctx context.Context, stores *store.Store, webhookManager *webhook.Manager, licenseService *enterprise.LicenseService, issue *store.IssueMessage, approvalSetting *storepb.WorkspaceApprovalSetting) error {
payload := issue.Payload
if payload.Approval != nil && payload.Approval.ApprovalFindingDone {
return nil
@@ -183,7 +183,7 @@ func findApprovalTemplateForIssue(ctx context.Context, stores *store.Store, b *b
}
// Step 2: Build CEL variables for evaluation
- celVarsList, done, err := buildCELVariablesForIssue(ctx, stores, b, issue)
+ celVarsList, done, err := buildCELVariablesForIssue(ctx, stores, issue)
if err != nil {
return nil, nil, false, errors.Wrap(err, "failed to build CEL variables for issue")
}
@@ -387,12 +387,12 @@ func buildFallbackCELVars(celVarsList []map[string]any) []map[string]any {
// buildCELVariablesForIssue builds the CEL variable maps for evaluating approval rules.
// Returns a list of CEL variable maps (one per task/component), done flag, and error.
// done=false means the caller should retry later (e.g., waiting for plan check runs).
-func buildCELVariablesForIssue(ctx context.Context, stores *store.Store, b *bus.Bus, issue *store.IssueMessage) ([]map[string]any, bool, error) {
+func buildCELVariablesForIssue(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) {
switch issue.Type {
case storepb.Issue_ROLE_GRANT:
return buildCELVariablesForRoleGrant(ctx, stores, issue)
case storepb.Issue_DATABASE_CHANGE:
- return buildCELVariablesForDatabaseChange(ctx, stores, b, issue)
+ return buildCELVariablesForDatabaseChange(ctx, stores, issue)
case storepb.Issue_DATABASE_EXPORT:
return buildCELVariablesForDataExport(ctx, stores, issue)
case storepb.Issue_ACCESS_GRANT:
@@ -543,44 +543,6 @@ func buildStatementSummaryResultMap(results []*storepb.PlanCheckRunResult_Result
return m
}
-func hasLegacyStatementSummaryResult(planCheckRun *store.PlanCheckRunMessage, targets []specTarget) bool {
- if planCheckRun == nil || planCheckRun.Status != store.PlanCheckRunStatusDone {
- return false
- }
-
- type databaseKey struct {
- InstanceID string
- DatabaseName string
- }
- sheetBackedTargets := map[databaseKey]struct{}{}
- for _, target := range targets {
- if target.sheetSha256 == "" || target.database == nil {
- continue
- }
- sheetBackedTargets[databaseKey{
- InstanceID: target.database.InstanceID,
- DatabaseName: target.database.DatabaseName,
- }] = struct{}{}
- }
- if len(sheetBackedTargets) == 0 {
- return false
- }
-
- for _, result := range planCheckRun.Result.GetResults() {
- if result.Type != storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT || result.SheetSha256 != "" {
- continue
- }
- instanceID, databaseName, err := common.GetInstanceDatabaseID(result.Target)
- if err != nil {
- continue
- }
- if _, ok := sheetBackedTargets[databaseKey{InstanceID: instanceID, DatabaseName: databaseName}]; ok {
- return true
- }
- }
- return false
-}
-
func isPlanCheckRunPendingApprovalEvaluation(planCheckRun *store.PlanCheckRunMessage) bool {
if planCheckRun == nil {
return false
@@ -588,31 +550,9 @@ func isPlanCheckRunPendingApprovalEvaluation(planCheckRun *store.PlanCheckRunMes
return planCheckRun.Status == store.PlanCheckRunStatusAvailable || planCheckRun.Status == store.PlanCheckRunStatusRunning
}
-func shouldRerunLegacyStatementSummaryResult(planCheckRun *store.PlanCheckRunMessage, targets []specTarget) bool {
- return hasLegacyStatementSummaryResult(planCheckRun, targets)
-}
-
-func rerunPlanChecksForApproval(ctx context.Context, stores *store.Store, b *bus.Bus, plan *store.PlanMessage) error {
- if b == nil {
- return errors.New("approval plan-check rerun requires bus")
- }
- if err := stores.CreatePlanCheckRun(ctx, &store.PlanCheckRunMessage{
- ProjectID: plan.ProjectID,
- PlanUID: plan.UID,
- Result: &storepb.PlanCheckRunResult{},
- }); err != nil {
- return errors.Wrap(err, "failed to create plan check run")
- }
- select {
- case b.PlanCheckTickleChan <- 0:
- default:
- }
- return nil
-}
-
// buildCELVariablesForDatabaseChange builds CEL variables for DATABASE_CHANGE issues.
// This includes DDL and DML operations.
-func buildCELVariablesForDatabaseChange(ctx context.Context, stores *store.Store, b *bus.Bus, issue *store.IssueMessage) ([]map[string]any, bool, error) {
+func buildCELVariablesForDatabaseChange(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) {
if issue.PlanUID == nil {
return nil, false, errors.Errorf("expected plan UID in issue %v", issue.UID)
}
@@ -640,13 +580,6 @@ func buildCELVariablesForDatabaseChange(ctx context.Context, stores *store.Store
return nil, false, errors.Wrap(err, "failed to unfold spec targets")
}
- if shouldRerunLegacyStatementSummaryResult(planCheckRun, targets) {
- if err := rerunPlanChecksForApproval(ctx, stores, b, plan); err != nil {
- return nil, false, err
- }
- return nil, false, nil
- }
-
statementSummaryResults := map[statementSummaryKey]*storepb.PlanCheckRunResult_Result{}
if planCheckRun != nil {
statementSummaryResults = buildStatementSummaryResultMap(planCheckRun.Result.GetResults())
diff --git a/backend/runner/approval/runner_test.go b/backend/runner/approval/runner_test.go
index 24cf6a56b0..1b0fcf736e 100644
--- a/backend/runner/approval/runner_test.go
+++ b/backend/runner/approval/runner_test.go
@@ -235,145 +235,6 @@ func TestBuildStatementSummaryResultMapUsesSheetSHA256(t *testing.T) {
}].GetSqlSummaryReport().GetAffectedRows())
}
-func TestHasLegacyStatementSummaryResultForSheetTarget(t *testing.T) {
- sheetTargets := []specTarget{
- {
- database: &store.DatabaseMessage{
- InstanceID: "prod",
- DatabaseName: "app",
- },
- sheetSha256: "sheet-a",
- },
- }
- tests := []struct {
- name string
- planCheckRun *store.PlanCheckRunMessage
- targets []specTarget
- want bool
- }{
- {
- name: "legacy summary result for sheet target",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/app",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- },
- },
- },
- },
- targets: sheetTargets,
- want: true,
- },
- {
- name: "sheet-tagged result is not legacy",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/app",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- SheetSha256: "sheet-a",
- },
- },
- },
- },
- targets: sheetTargets,
- },
- {
- name: "non-sheet target is not legacy",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/app",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- },
- },
- },
- },
- targets: []specTarget{
- {
- database: &store.DatabaseMessage{
- InstanceID: "prod",
- DatabaseName: "app",
- },
- },
- },
- },
- {
- name: "non-summary result is not legacy",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/app",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_ADVISE,
- },
- },
- },
- },
- targets: sheetTargets,
- },
- {
- name: "invalid target is not legacy",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "bad-target",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- },
- },
- },
- },
- targets: sheetTargets,
- },
- {
- name: "non-matching target is not legacy",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/other",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- },
- },
- },
- },
- targets: sheetTargets,
- },
- {
- name: "non-DONE status is not legacy",
- planCheckRun: &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusAvailable,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/app",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- },
- },
- },
- },
- targets: sheetTargets,
- },
- }
-
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- require.Equal(t, tt.want, hasLegacyStatementSummaryResult(tt.planCheckRun, tt.targets))
- })
- }
-}
-
func TestIsPlanCheckRunPendingApprovalEvaluation(t *testing.T) {
tests := []struct {
name string
@@ -406,34 +267,3 @@ func TestIsPlanCheckRunPendingApprovalEvaluation(t *testing.T) {
})
}
}
-
-func TestShouldRerunLegacyStatementSummaryResult(t *testing.T) {
- targets := []specTarget{
- {
- database: &store.DatabaseMessage{
- InstanceID: "prod",
- DatabaseName: "app",
- },
- sheetSha256: "sheet-a",
- },
- }
- planCheckRun := &store.PlanCheckRunMessage{
- Status: store.PlanCheckRunStatusDone,
- Result: &storepb.PlanCheckRunResult{
- Results: []*storepb.PlanCheckRunResult_Result{
- {
- Target: "instances/prod/databases/app",
- Type: storepb.PlanCheckType_PLAN_CHECK_TYPE_STATEMENT_SUMMARY_REPORT,
- },
- },
- },
- }
-
- require.True(t, shouldRerunLegacyStatementSummaryResult(planCheckRun, targets))
-
- planCheckRun.Result.Results[0].SheetSha256 = "sheet-a"
- require.False(t, shouldRerunLegacyStatementSummaryResult(planCheckRun, targets))
-
- planCheckRun.Result.Results[0].SheetSha256 = ""
- require.True(t, shouldRerunLegacyStatementSummaryResult(planCheckRun, targets))
-}