Skip to content

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

feat: impl issue comment update statement/earliestAllowedTime/backup (#11547)

p0ny8633fce92b57
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index d5d79a74a5..77843b0816 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -14,6 +14,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/testing/protocmp"
+ "google.golang.org/protobuf/types/known/timestamppb"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
@@ -1248,6 +1249,25 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePla
for _, statementUpdate := range statementUpdates {
task := tasksMap[statementUpdate.TaskID]
+
+ if err := func() error {
+ oldSheet := common.FormatSheet(issue.Project.ResourceID, statementUpdate.OldSheetID)
+ newSheet := common.FormatSheet(issue.Project.ResourceID, statementUpdate.NewSheetID)
+ return s.store.CreateIssueComment(ctx, &store.IssueCommentMessage{
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_TaskUpdate_{
+ TaskUpdate: &storepb.IssueCommentPayload_TaskUpdate{
+ Tasks: []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID)},
+ FromSheet: &oldSheet,
+ ToSheet: &newSheet,
+ },
+ },
+ },
+ }, user.ID)
+ }(); err != nil {
+ slog.Warn("failed to create issue comments for statement update", "issueUID", issue.UID, log.BBError(err))
+ }
+
if err := func() error {
payload, err := json.Marshal(statementUpdate)
if err != nil {
@@ -1270,6 +1290,23 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePla
}
for _, earliestUpdate := range earliestUpdates {
task := tasksMap[earliestUpdate.TaskID]
+
+ if err := func() error {
+ return s.store.CreateIssueComment(ctx, &store.IssueCommentMessage{
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_TaskUpdate_{
+ TaskUpdate: &storepb.IssueCommentPayload_TaskUpdate{
+ Tasks: []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID)},
+ FromEarliestAllowedTime: timestamppb.New(time.Unix(earliestUpdate.OldEarliestAllowedTs, 0)),
+ ToEarliestAllowedTime: timestamppb.New(time.Unix(earliestUpdate.NewEarliestAllowedTs, 0)),
+ },
+ },
+ },
+ }, user.ID)
+ }(); err != nil {
+ slog.Warn("failed to create issue comments for earliest allowed time update", "issueUID", issue.UID, log.BBError(err))
+ }
+
if err := func() error {
payload, err := json.Marshal(earliestUpdate)
if err != nil {
diff --git a/backend/common/resource_name.go b/backend/common/resource_name.go
index 4131fb2a69..c3069f9c9f 100644
--- a/backend/common/resource_name.go
+++ b/backend/common/resource_name.go
@@ -575,6 +575,10 @@ func FormatRole(role string) string {
return fmt.Sprintf("%s%s", RolePrefix, role)
}
+func FormatSheet(projectID string, sheetUID int) string {
+ return fmt.Sprintf("%s%s/%s%d", ProjectNamePrefix, projectID, SheetIDPrefix, sheetUID)
+}
+
func FormatTask(projectID string, pipelineUID, stageUID, taskUID int) string {
return fmt.Sprintf("%s%s/%s%d/%s%d/%s%d", ProjectNamePrefix, projectID, RolloutPrefix, pipelineUID, StagePrefix, stageUID, TaskPrefix, taskUID)
}
diff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.go
index 8df43a4f2d..88289f0149 100644
--- a/backend/runner/taskrun/data_update_executor.go
+++ b/backend/runner/taskrun/data_update_executor.go
@@ -99,6 +99,9 @@ func (exec *DataUpdateExecutor) backupData(
if err != nil {
return errors.Wrapf(err, "failed to find issue for pipeline %v", task.PipelineID)
}
+ if issue == nil {
+ return errors.Errorf("issue not found for pipeline %v", task.PipelineID)
+ }
backupInstanceID, backupDatabaseName, err := common.GetInstanceDatabaseID(payload.PreUpdateBackupDetail.Database)
if err != nil {
@@ -159,6 +162,25 @@ func (exec *DataUpdateExecutor) backupData(
log.BBError(err),
)
}
+
+ if err := exec.store.CreateIssueComment(ctx, &store.IssueCommentMessage{
+ IssueUID: issue.UID,
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_TaskPriorBackup_{
+ TaskPriorBackup: &storepb.IssueCommentPayload_TaskPriorBackup{
+ Task: common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.StageID, task.ID),
+ Tables: []*storepb.IssueCommentPayload_TaskPriorBackup_Table{
+ {
+ Schema: "",
+ Table: statement.TableName,
+ },
+ },
+ },
+ },
+ },
+ }, api.SystemBotID); err != nil {
+ slog.Warn("failed to create issue comment", "task", task.ID, log.BBError(err))
+ }
}
if err := exec.schemaSyncer.SyncDatabaseSchema(ctx, backupDatabase, true /* force */); err != nil {