Skip to content

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

feat: allow to return rollout without tasks (#16848)

p0ny20cf11c8cc19
diff --git a/action/command/rollout.go b/action/command/rollout.go
index 7724bac298..f7dc17aae8 100644
--- a/action/command/rollout.go
+++ b/action/command/rollout.go
@@ -103,11 +103,6 @@ func runRollout(w *world.World) func(command *cobra.Command, _ []string) error {
},
})
if err != nil {
- // Check for specific error indicating no tasks were created
- if strings.Contains(err.Error(), "there is no tasks created from the plan") {
- w.Logger.Warn("no tasks created from the plan, skip rollout")
- return nil
- }
return errors.Wrapf(err, "failed to create plan")
}
plan = planCreated
@@ -288,6 +283,10 @@ func waitForRollout(ctx context.Context, w *world.World, client *Client, pending
}
}),
"pendingStages", pendingStages)
+ if len(pendingStages) == 0 && len(rollout.Stages) == 0 {
+ w.Logger.Info("no stages in the rollout. exiting...")
+ return nil
+ }
targetStageFound := false
for _, stage := range rollout.GetStages() {
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 2c10dade93..0c3eeec008 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -86,9 +86,6 @@ func (s *RolloutService) PreviewRollout(ctx context.Context, req *connect.Reques
if err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("failed to get pipeline create, error: %v", err))
}
- if len(rollout.Tasks) == 0 {
- return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("plan has no stage created, hint: check deployment config setting that the target database is in a stage"))
- }
rolloutV1, err := convertToRollout(ctx, s.store, project, rollout)
if err != nil {
@@ -237,9 +234,6 @@ func (s *RolloutService) CreateRollout(ctx context.Context, req *connect.Request
if err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("failed to get pipeline create, error: %v", err))
}
- if len(pipelineCreate.Tasks) == 0 {
- return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("no database matched for deployment, hint: check deployment config setting that the target database is in a stage"))
- }
if isChangeDatabasePlan(plan.Config.GetSpecs()) {
pipelineCreate, err = getPipelineCreateToTargetStage(ctx, s.store, plan.Config.GetDeployment(), pipelineCreate, request.Target)
if err != nil {
@@ -973,9 +967,6 @@ func GetPipelineCreate(ctx context.Context, s *store.Store, sheetManager *sheet.
}
taskCreates = append(taskCreates, tcs...)
}
- if len(taskCreates) == 0 {
- return nil, errors.Errorf("there is no tasks created from the plan")
- }
// Filter out tasks not in deployment environments
filteredTasks := filterTasksByEnvironments(taskCreates, environmentIndex)
diff --git a/backend/tests/action_test.go b/backend/tests/action_test.go
index 4ed9e84c72..c2bdfd1a7b 100644
--- a/backend/tests/action_test.go
+++ b/backend/tests/action_test.go
@@ -713,7 +713,7 @@ func TestActionErrorScenarios(t *testing.T) {
"--target-stage", "environments/prod",
)
a.NoError(err)
- a.Contains(result.Stderr, "no tasks created from the plan", "Expected no tasks created error in stderr")
+ a.Contains(result.Stderr, "no stages in the rollout. exiting...", "Expected no stages in the rollout error in stderr")
// Should create a release with no files
releases, err := ctl.releaseServiceClient.ListReleases(ctx, connect.NewRequest(&v1pb.ListReleasesRequest{
diff --git a/backend/tests/gitops_test.go b/backend/tests/gitops_test.go
index ef66296dbc..de8e709471 100644
--- a/backend/tests/gitops_test.go
+++ b/backend/tests/gitops_test.go
@@ -306,6 +306,31 @@ func TestGitOpsRollout(t *testing.T) {
a.Equal(createReleaseResp.Msg.Name, revision.Release, "Revision should reference the correct release")
a.NotEmpty(revision.Version, "Revision should have a version")
a.NotNil(revision.CreateTime, "Revision should have a create time")
+
+ // Call CreateRollout on the finished plan.
+ // the rollout name is the same as the rollout created above.
+ rolloutResp2, err := ctl.rolloutServiceClient.CreateRollout(ctx, connect.NewRequest(&v1pb.CreateRolloutRequest{
+ Parent: project.Name,
+ Rollout: &v1pb.Rollout{
+ Plan: plan.Name,
+ },
+ }))
+ a.NoError(err)
+ a.NotNil(rolloutResp2)
+ a.Equal(rollout.Name, rolloutResp2.Msg.Name)
+
+ // Call CreateRollout with ValidateOnly on the finished plan.
+ // the rollout should contain zero stages.
+ rolloutResp3, err := ctl.rolloutServiceClient.CreateRollout(ctx, connect.NewRequest(&v1pb.CreateRolloutRequest{
+ Parent: project.Name,
+ Rollout: &v1pb.Rollout{
+ Plan: plan.Name,
+ },
+ ValidateOnly: true,
+ }))
+ a.NoError(err)
+ a.NotNil(rolloutResp3)
+ a.Empty(rolloutResp3.Msg.Stages)
}
// TestGitOpsRolloutMultiTarget tests a more complex GitOps scenario:
@@ -558,6 +583,31 @@ func TestGitOpsRolloutMultiTarget(t *testing.T) {
expectedVersions := []string{"1.0.0", "1.0.1", "1.0.2"}
a.ElementsMatch(testVersions, expectedVersions, "Test database should have the expected migration versions")
a.ElementsMatch(prodVersions, expectedVersions, "Prod database should have the expected migration versions")
+
+ // Call CreateRollout on the finished plan.
+ // the rollout name is the same as the rollout created above.
+ rolloutResp2, err := ctl.rolloutServiceClient.CreateRollout(ctx, connect.NewRequest(&v1pb.CreateRolloutRequest{
+ Parent: project.Name,
+ Rollout: &v1pb.Rollout{
+ Plan: plan.Name,
+ },
+ }))
+ a.NoError(err)
+ a.NotNil(rolloutResp2)
+ a.Equal(rollout.Name, rolloutResp2.Msg.Name)
+
+ // Call CreateRollout with ValidateOnly on the finished plan.
+ // the rollout should contain zero stages.
+ rolloutResp3, err := ctl.rolloutServiceClient.CreateRollout(ctx, connect.NewRequest(&v1pb.CreateRolloutRequest{
+ Parent: project.Name,
+ Rollout: &v1pb.Rollout{
+ Plan: plan.Name,
+ },
+ ValidateOnly: true,
+ }))
+ a.NoError(err)
+ a.NotNil(rolloutResp3)
+ a.Empty(rolloutResp3.Msg.Stages)
}
// TestGitOpsCheckAppliedButChanged tests that CheckRelease detects files that have been applied but with different content.