Skip to content

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

chore: GitOps create issue before rollout (#8364)

Danny Xu928da9dbfc60
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index ca2a913583..451724826f 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -1643,13 +1643,6 @@ func (s *Service) createIssueFromMigrationDetailsV2(ctx context.Context, project
if err != nil {
return errors.Wrapf(err, "failed to create plan")
}
- rollout, err := s.rolloutService.CreateRollout(childCtx, &v1pb.CreateRolloutRequest{
- Parent: fmt.Sprintf("projects/%s", project.ResourceID),
- Plan: plan.Name,
- })
- if err != nil {
- return errors.Wrapf(err, "failed to create rollout")
- }
issue, err := s.issueService.CreateIssue(childCtx, &v1pb.CreateIssueRequest{
Parent: fmt.Sprintf("projects/%s", project.ResourceID),
Issue: &v1pb.Issue{
@@ -1658,12 +1651,18 @@ func (s *Service) createIssueFromMigrationDetailsV2(ctx context.Context, project
Type: v1pb.Issue_DATABASE_CHANGE,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
Plan: plan.Name,
- Rollout: rollout.Name,
},
})
if err != nil {
return errors.Wrapf(err, "failed to create issue")
}
+ if _, err := s.rolloutService.CreateRollout(childCtx, &v1pb.CreateRolloutRequest{
+ Parent: fmt.Sprintf("projects/%s", project.ResourceID),
+ Plan: plan.Name,
+ }); err != nil {
+ return errors.Wrapf(err, "failed to create rollout")
+ }
+
issueUID, err := strconv.Atoi(issue.Uid)
if err != nil {
return err
diff --git a/backend/tests/backup_restore_test.go b/backend/tests/backup_restore_test.go
index a8fb091b84..57a23fa021 100644
--- a/backend/tests/backup_restore_test.go
+++ b/backend/tests/backup_restore_test.go
@@ -67,8 +67,6 @@ func TestRestoreToNewDatabase(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -76,11 +74,12 @@ func TestRestoreToNewDatabase(t *testing.T) {
Title: fmt.Sprintf("restore database %s", database.Name),
Description: fmt.Sprintf("restore database %s", database.Name),
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
err = ctl.waitRollout(ctx, issue.Name, rollout.Name)
a.NoError(err)
@@ -160,8 +159,6 @@ func TestPITRGeneral(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -169,11 +166,12 @@ func TestPITRGeneral(t *testing.T) {
Title: "restore database",
Description: "restore database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
// Restore stage.
err = ctl.rolloutAndWaitTask(ctx, issue.Name, rollout.Name)
@@ -242,8 +240,6 @@ func TestPITRDropDatabase(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -251,11 +247,12 @@ func TestPITRDropDatabase(t *testing.T) {
Title: "restore database",
Description: "restore database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
// Restore stage.
err = ctl.rolloutAndWaitTask(ctx, issue.Name, rollout.Name)
@@ -308,8 +305,6 @@ func TestPITRTwice(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -317,11 +312,12 @@ func TestPITRTwice(t *testing.T) {
Title: "restore database",
Description: "restore database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
// Restore stage.
err = ctl.rolloutAndWaitTask(ctx, issue.Name, rollout.Name)
@@ -380,8 +376,6 @@ func TestPITRTwice(t *testing.T) {
},
})
a.NoError(err)
- rollout, err = ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err = ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -389,11 +383,12 @@ func TestPITRTwice(t *testing.T) {
Title: "restore database",
Description: "restore database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err = ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
// Restore stage.
err = ctl.rolloutAndWaitTask(ctx, issue.Name, rollout.Name)
@@ -480,8 +475,6 @@ func TestPITRToNewDatabaseInAnotherInstance(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -489,11 +482,12 @@ func TestPITRToNewDatabaseInAnotherInstance(t *testing.T) {
Title: "restore database",
Description: "restore database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
err = ctl.waitRollout(ctx, issue.Name, rollout.Name)
a.NoError(err)
@@ -539,8 +533,6 @@ func TestPITRInvalidTimePoint(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -548,11 +540,12 @@ func TestPITRInvalidTimePoint(t *testing.T) {
Title: "restore database",
Description: "restore database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
err = ctl.rolloutAndWaitTask(ctx, issue.Name, rollout.Name)
a.Error(err)
diff --git a/backend/tests/database.go b/backend/tests/database.go
index 52c514f60e..3040196d89 100644
--- a/backend/tests/database.go
+++ b/backend/tests/database.go
@@ -54,19 +54,12 @@ func (ctl *controller) createDatabaseV2(ctx context.Context, project *v1pb.Proje
if err != nil {
return err
}
-
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- if err != nil {
- return err
- }
-
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
Title: fmt.Sprintf("create database %q", databaseName),
Description: fmt.Sprintf("This creates a database %q.", databaseName),
Plan: plan.Name,
- Rollout: rollout.Name,
Type: v1pb.Issue_DATABASE_CHANGE,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
@@ -74,6 +67,10 @@ func (ctl *controller) createDatabaseV2(ctx context.Context, project *v1pb.Proje
if err != nil {
return err
}
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ if err != nil {
+ return err
+ }
if err := ctl.waitRollout(ctx, issue.Name, rollout.Name); err != nil {
return err
@@ -129,19 +126,12 @@ func (ctl *controller) createDatabaseFromBackup(ctx context.Context, project *v1
if err != nil {
return err
}
-
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- if err != nil {
- return err
- }
-
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
Title: fmt.Sprintf("create database %q", databaseName),
Description: fmt.Sprintf("This creates a database %q.", databaseName),
Plan: plan.Name,
- Rollout: rollout.Name,
Type: v1pb.Issue_DATABASE_CHANGE,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
@@ -149,6 +139,10 @@ func (ctl *controller) createDatabaseFromBackup(ctx context.Context, project *v1
if err != nil {
return err
}
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ if err != nil {
+ return err
+ }
if err := ctl.waitRollout(ctx, issue.Name, rollout.Name); err != nil {
return err
diff --git a/backend/tests/rollout.go b/backend/tests/rollout.go
index f2f7aee8f1..2a9ed9027f 100644
--- a/backend/tests/rollout.go
+++ b/backend/tests/rollout.go
@@ -43,10 +43,6 @@ func (ctl *controller) changeDatabaseWithConfig(ctx context.Context, project *v1
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "failed to create plan")
}
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- if err != nil {
- return nil, nil, nil, errors.Wrapf(err, "failed to create rollout")
- }
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -54,13 +50,16 @@ func (ctl *controller) changeDatabaseWithConfig(ctx context.Context, project *v1
Title: "change database",
Description: "change database",
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "failed to create issue")
}
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ if err != nil {
+ return nil, nil, nil, errors.Wrapf(err, "failed to create rollout")
+ }
err = ctl.waitRollout(ctx, issue.Name, rollout.Name)
if err != nil {
return nil, nil, nil, err
diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.go
index 548cfa0012..65170dbbe6 100644
--- a/backend/tests/schema_update_test.go
+++ b/backend/tests/schema_update_test.go
@@ -2071,8 +2071,6 @@ func TestMarkTaskAsDone(t *testing.T) {
},
})
a.NoError(err)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: ctl.project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: ctl.project.Name,
Issue: &v1pb.Issue{
@@ -2080,11 +2078,12 @@ func TestMarkTaskAsDone(t *testing.T) {
Title: fmt.Sprintf("change database %s", database.Name),
Description: fmt.Sprintf("change database %s", database.Name),
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: ctl.project.Name, Plan: plan.Name})
+ a.NoError(err)
// Skip the task.
for _, stage := range rollout.Stages {
diff --git a/backend/tests/sql_review_test.go b/backend/tests/sql_review_test.go
index 4746816a0c..ab80e6da02 100644
--- a/backend/tests/sql_review_test.go
+++ b/backend/tests/sql_review_test.go
@@ -467,8 +467,6 @@ func createIssueAndReturnSQLReviewResult(ctx context.Context, a *require.Asserti
a.NotNil(result)
a.Len(result.Results, 1)
a.Equal(v1pb.PlanCheckRun_Result_SUCCESS, result.Results[0].Status)
- rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
- a.NoError(err)
issue, err := ctl.issueServiceClient.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: project.Name,
Issue: &v1pb.Issue{
@@ -476,11 +474,12 @@ func createIssueAndReturnSQLReviewResult(ctx context.Context, a *require.Asserti
Title: fmt.Sprintf("change database %s", database.Name),
Description: fmt.Sprintf("change database %s", database.Name),
Plan: plan.Name,
- Rollout: rollout.Name,
Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
},
})
a.NoError(err)
+ rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, &v1pb.CreateRolloutRequest{Parent: project.Name, Plan: plan.Name})
+ a.NoError(err)
time.Sleep(time.Second)
err = ctl.waitRollout(ctx, issue.Name, rollout.Name)
a.NoError(err)