Skip to content

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

fix: backup patch should use pointers to avoid setting existing columns to empty (#2357)

h3n4l23f2ebf7662f
diff --git a/api/backup.go b/api/backup.go
index 0674c4f32c..af6d93b473 100644
--- a/api/backup.go
+++ b/api/backup.go
@@ -164,9 +164,9 @@ type BackupPatch struct {
UpdaterID int
// Domain specific fields
- Status string
- Comment string
- Payload string
+ Status *string
+ Comment *string
+ Payload *string
}
// BackupSetting is the backup setting for a database.
diff --git a/server/backup_runner.go b/server/backup_runner.go
index f69f00948b..be29362502 100644
--- a/server/backup_runner.go
+++ b/server/backup_runner.go
@@ -182,6 +182,7 @@ func (r *BackupRunner) purgeBackup(ctx context.Context, backup *api.Backup) erro
archive := api.Archived
backupPatch := api.BackupPatch{
ID: backup.ID,
+ UpdaterID: api.SystemBotID,
RowStatus: &archive,
}
if _, err := r.server.store.PatchBackup(ctx, &backupPatch); err != nil {
diff --git a/server/task_executor_database_backup.go b/server/task_executor_database_backup.go
index ae30349d49..23e3e831e8 100644
--- a/server/task_executor_database_backup.go
+++ b/server/task_executor_database_backup.go
@@ -57,17 +57,20 @@ func (exec *DatabaseBackupTaskExecutor) RunOnce(ctx context.Context, server *Ser
)
backupPayload, backupErr := exec.backupDatabase(ctx, server, task.Instance, task.Database.Name, backup)
+ backupStatus := string(api.BackupStatusDone)
+ comment := ""
+ if backupErr != nil {
+ backupStatus = string(api.BackupStatusFailed)
+ comment = backupErr.Error()
+ }
backupPatch := api.BackupPatch{
ID: backup.ID,
- Status: string(api.BackupStatusDone),
+ Status: &backupStatus,
UpdaterID: api.SystemBotID,
- Comment: "",
- Payload: backupPayload,
- }
- if backupErr != nil {
- backupPatch.Status = string(api.BackupStatusFailed)
- backupPatch.Comment = backupErr.Error()
+ Comment: &comment,
+ Payload: &backupPayload,
}
+
if _, err := server.store.PatchBackup(ctx, &backupPatch); err != nil {
return true, nil, errors.Wrap(err, "failed to patch backup")
}
diff --git a/store/backup.go b/store/backup.go
index 36983d76ba..909d3a748d 100644
--- a/store/backup.go
+++ b/store/backup.go
@@ -535,18 +535,23 @@ func (*Store) findBackupImpl(ctx context.Context, tx *sql.Tx, find *api.BackupFi
// patchBackupImpl updates a backup by ID. Returns the new state of the backup after update.
func (*Store) patchBackupImpl(ctx context.Context, tx *sql.Tx, patch *api.BackupPatch) (*backupRaw, error) {
// Build UPDATE clause.
- set, args := []string{}, []interface{}{}
- set, args = append(set, fmt.Sprintf("updater_id = $%d", len(args)+1)), append(args, patch.UpdaterID)
- set, args = append(set, fmt.Sprintf("status = $%d", len(args)+1)), append(args, patch.Status)
- set, args = append(set, fmt.Sprintf("comment = $%d", len(args)+1)), append(args, patch.Comment)
+ set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}
if v := patch.RowStatus; v != nil {
set, args = append(set, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
- if patch.Payload == "" {
- patch.Payload = "{}"
+ if v := patch.Status; v != nil {
+ set, args = append(set, fmt.Sprintf("status = $%d", len(args)+1)), append(args, *v)
+ }
+ if v := patch.Comment; v != nil {
+ set, args = append(set, fmt.Sprintf("comment = $%d", len(args)+1)), append(args, *v)
+ }
+ if v := patch.Payload; v != nil {
+ if *v == "" {
+ *v = "{}"
+ }
+ set, args = append(set, fmt.Sprintf("payload = $%d", len(args)+1)), append(args, *v)
}
- set, args = append(set, fmt.Sprintf("payload = $%d", len(args)+1)), append(args, patch.Payload)
args = append(args, patch.ID)
var backupRaw backupRaw