Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: change the name of a backup (#10065)
Danny Xu63f058515f50
diff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.goindex b26d002a63..47b9a8e283 100644--- a/backend/runner/taskrun/data_update_executor.go+++ b/backend/runner/taskrun/data_update_executor.go@@ -68,7 +68,7 @@ func (exec *DataUpdateExecutor) RunOnce(ctx context.Context, driverCtx context.Cif err != nil {return true, nil, err}- if err := exec.backupData(ctx, driverCtx, statement, payload, task, taskRunUID); err != nil {+ if err := exec.backupData(ctx, driverCtx, statement, payload, task); err != nil {return true, nil, err}version := model.Version{Version: payload.SchemaVersion}@@ -81,7 +81,6 @@ func (exec *DataUpdateExecutor) backupData(statement string,payload *api.TaskDatabaseDataUpdatePayload,task *store.TaskMessage,- taskRunUID int,) error {if payload.PreUpdateBackupDetail.Database == "" {return nil@@ -114,7 +113,7 @@ func (exec *DataUpdateExecutor) backupData(return err}- suffix := fmt.Sprintf("%d", taskRunUID)+ suffix := time.Now().Format("20060102150405")selectIntoStatement := updateToSelect(statement, backupDatabaseName, suffix)if _, err := driver.Execute(driverCtx, selectIntoStatement, false /* createDatabase */, db.ExecuteOptions{}); err != nil {return err@@ -137,6 +136,7 @@ func updateToSelect(statement, databaseName, suffix string) string {updateIndex := strings.Index(lowerStatement, "update")setIndex := strings.Index(lowerStatement, "set")tableName := strings.Trim(statement[updateIndex+6:setIndex], " \n\t")- targetTableName := fmt.Sprintf("%s.%s%s", databaseName, tableName, suffix)+ tableName = strings.Trim(tableName, "`")+ targetTableName := fmt.Sprintf("`%s`.`%s_%s`", databaseName, tableName, suffix)return fmt.Sprintf("CREATE TABLE %s LIKE %s; INSERT INTO %s SELECT * FROM %s %s", targetTableName, tableName, targetTableName, tableName, condition)}diff --git a/backend/runner/taskrun/data_update_executor_test.go b/backend/runner/taskrun/data_update_executor_test.goindex 274022e430..b7ad8509fb 100644--- a/backend/runner/taskrun/data_update_executor_test.go+++ b/backend/runner/taskrun/data_update_executor_test.go@@ -8,5 +8,5 @@ import (func TestUpdateToSelect(t *testing.T) {got := updateToSelect("UPDATE hello SET column1 = value1, column2 = value2 WHERE id > 3;", "todozp", "113")- assert.Equal(t, "CREATE TABLE todozp.hello113 LIKE hello; INSERT INTO todozp.hello113 SELECT * FROM hello WHERE id > 3;", got)+ assert.Equal(t, "CREATE TABLE `todozp`.`hello_113` LIKE hello; INSERT INTO `todozp`.`hello_113` SELECT * FROM hello WHERE id > 3;", got)}