Skip to content

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

fix: plan check run sheet name (#9120)

p0ny03ef1303c783
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index f7033c16a9..b4dd5f6503 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -326,7 +326,7 @@ func (s *RolloutService) CreateRollout(ctx context.Context, request *v1pb.Create
// ListPlanCheckRuns lists plan check runs for the plan.
func (s *RolloutService) ListPlanCheckRuns(ctx context.Context, request *v1pb.ListPlanCheckRunsRequest) (*v1pb.ListPlanCheckRunsResponse, error) {
- planUID, err := common.GetPlanID(request.Parent)
+ projectID, planUID, err := common.GetProjectIDPlanID(request.Parent)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
@@ -336,7 +336,7 @@ func (s *RolloutService) ListPlanCheckRuns(ctx context.Context, request *v1pb.Li
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list plan check runs, error: %v", err)
}
- converted, err := convertToPlanCheckRuns(ctx, s.store, request.Parent, planCheckRuns)
+ converted, err := convertToPlanCheckRuns(ctx, s.store, projectID, planUID, planCheckRuns)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert plan check runs, error: %v", err)
}
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index 7181183205..56750c934d 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -307,10 +307,10 @@ func convertDatabaseLabels(labelsMap map[string]string) (string, error) {
return string(labelsJSON), nil
}
-func convertToPlanCheckRuns(ctx context.Context, s *store.Store, parent string, runs []*store.PlanCheckRunMessage) ([]*v1pb.PlanCheckRun, error) {
+func convertToPlanCheckRuns(ctx context.Context, s *store.Store, projectID string, planUID int64, runs []*store.PlanCheckRunMessage) ([]*v1pb.PlanCheckRun, error) {
var planCheckRuns []*v1pb.PlanCheckRun
for _, run := range runs {
- converted, err := convertToPlanCheckRun(ctx, s, parent, run)
+ converted, err := convertToPlanCheckRun(ctx, s, projectID, planUID, run)
if err != nil {
return nil, errors.Wrapf(err, "failed to convert plan check run")
}
@@ -319,9 +319,9 @@ func convertToPlanCheckRuns(ctx context.Context, s *store.Store, parent string,
return planCheckRuns, nil
}
-func convertToPlanCheckRun(ctx context.Context, s *store.Store, parent string, run *store.PlanCheckRunMessage) (*v1pb.PlanCheckRun, error) {
+func convertToPlanCheckRun(ctx context.Context, s *store.Store, projectID string, planUID int64, run *store.PlanCheckRunMessage) (*v1pb.PlanCheckRun, error) {
converted := &v1pb.PlanCheckRun{
- Name: fmt.Sprintf("%s/%s%d", parent, common.PlanCheckRunPrefix, run.UID),
+ Name: fmt.Sprintf("%s%s/%s%d/%s%d", common.ProjectNamePrefix, projectID, common.PlanPrefix, planUID, common.PlanCheckRunPrefix, run.UID),
Uid: fmt.Sprintf("%d", run.UID),
CreateTime: timestamppb.New(time.Unix(run.CreatedTs, 0)),
Type: convertToPlanCheckRunType(run.Type),
@@ -340,7 +340,7 @@ func convertToPlanCheckRun(ctx context.Context, s *store.Store, parent string, r
if sheet == nil {
return nil, errors.Errorf("sheet not found for uid %d", sheetUID)
}
- converted.Sheet = fmt.Sprintf("%s/%s%d", parent, common.SheetIDPrefix, sheet.UID)
+ converted.Sheet = fmt.Sprintf("%s%s/%s%d", common.ProjectNamePrefix, projectID, common.SheetIDPrefix, sheet.UID)
}
instanceUID := int(run.Config.InstanceUid)
diff --git a/backend/common/resource_name.go b/backend/common/resource_name.go
index 32c68e56dd..78c8e02009 100644
--- a/backend/common/resource_name.go
+++ b/backend/common/resource_name.go
@@ -308,6 +308,19 @@ func GetPlanID(name string) (int64, error) {
return planID, nil
}
+// GetProjectIDPlanID returns the project ID and plan ID from a resource name.
+func GetProjectIDPlanID(name string) (string, int64, error) {
+ tokens, err := GetNameParentTokens(name, ProjectNamePrefix, PlanPrefix)
+ if err != nil {
+ return "", 0, err
+ }
+ planID, err := strconv.ParseInt(tokens[1], 10, 64)
+ if err != nil {
+ return "", 0, errors.Errorf("invalid plan ID %q", tokens[1])
+ }
+ return tokens[0], planID, nil
+}
+
// GetProjectIDRolloutID returns the project ID and rollout ID from a resource name.
func GetProjectIDRolloutID(name string) (string, int, error) {
tokens, err := GetNameParentTokens(name, ProjectNamePrefix, RolloutPrefix)