Skip to content

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

chore: delete stale plan checks (#15933)

Danny Xu09249927d95f
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 227acbb2fd..0ac074e9e0 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -1117,7 +1117,7 @@ func (s *IssueService) UpdateIssue(ctx context.Context, request *v1pb.UpdateIssu
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan check runs for plan, error: %v", err)
}
- if err := s.store.CreatePlanCheckRuns(ctx, planCheckRuns...); err != nil {
+ if err := s.store.CreatePlanCheckRuns(ctx, plan, planCheckRuns...); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create plan check runs, error: %v", err)
}
}
diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.go
index 76c163f9b5..67d59b6c5d 100644
--- a/backend/api/v1/plan_service.go
+++ b/backend/api/v1/plan_service.go
@@ -273,7 +273,7 @@ func (s *PlanService) CreatePlan(ctx context.Context, request *v1pb.CreatePlanRe
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan check runs for plan, error: %v", err)
}
- if err := s.store.CreatePlanCheckRuns(ctx, planCheckRuns...); err != nil {
+ if err := s.store.CreatePlanCheckRuns(ctx, plan, planCheckRuns...); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create plan check runs, error: %v", err)
}
}
@@ -783,7 +783,7 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlanRe
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan check runs for plan, error: %v", err)
}
- if err := s.store.CreatePlanCheckRuns(ctx, planCheckRuns...); err != nil {
+ if err := s.store.CreatePlanCheckRuns(ctx, updatedPlan, planCheckRuns...); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create plan check runs, error: %v", err)
}
}
@@ -846,7 +846,7 @@ func (s *PlanService) RunPlanChecks(ctx context.Context, request *v1pb.RunPlanCh
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan check runs for plan, error: %v", err)
}
- if err := s.store.CreatePlanCheckRuns(ctx, planCheckRuns...); err != nil {
+ if err := s.store.CreatePlanCheckRuns(ctx, plan, planCheckRuns...); err != nil {
return nil, status.Errorf(codes.Internal, "failed to create plan check runs, error: %v", err)
}
diff --git a/backend/store/plan_check_run.go b/backend/store/plan_check_run.go
index 09d2bec990..0d28049634 100644
--- a/backend/store/plan_check_run.go
+++ b/backend/store/plan_check_run.go
@@ -69,7 +69,7 @@ type FindPlanCheckRunMessage struct {
}
// CreatePlanCheckRuns creates new plan check runs.
-func (s *Store) CreatePlanCheckRuns(ctx context.Context, creates ...*PlanCheckRunMessage) error {
+func (s *Store) CreatePlanCheckRuns(ctx context.Context, plan *PlanMessage, creates ...*PlanCheckRunMessage) error {
if len(creates) == 0 {
return nil
}
@@ -112,10 +112,18 @@ func (s *Store) CreatePlanCheckRuns(ctx context.Context, creates ...*PlanCheckRu
return err
}
}
- if _, err := s.db.ExecContext(ctx, query.String(), values...); err != nil {
+ txn, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return err
+ }
+ defer txn.Rollback()
+ if _, err := txn.ExecContext(ctx, "DELETE FROM plan_check_run WHERE plan_id = $1", plan.UID); err != nil {
+ return errors.Wrapf(err, "failed to delete plan check run for plan %d", plan.UID)
+ }
+ if _, err := txn.ExecContext(ctx, query.String(), values...); err != nil {
return errors.Wrapf(err, "failed to execute insert")
}
- return nil
+ return txn.Commit()
}
// ListPlanCheckRuns returns a list of plan check runs based on find.