Skip to content

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

chore: backup issue comment (#10124)

Danny Xu4eba1b0ef011
diff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.go
index dd22936e8e..919adab01d 100644
--- a/backend/runner/taskrun/data_update_executor.go
+++ b/backend/runner/taskrun/data_update_executor.go
@@ -118,7 +118,7 @@ func (exec *DataUpdateExecutor) backupData(
}
suffix := time.Now().Format("20060102150405")
- selectIntoStatement, targetTableName := updateToSelect(statement, backupDatabaseName, suffix)
+ selectIntoStatement, targetTableName := updateToSelect(statement, backupDatabaseName, suffix, issue.UID)
if _, err := driver.Execute(driverCtx, selectIntoStatement, false /* createDatabase */, db.ExecuteOptions{}); err != nil {
return err
}
@@ -159,7 +159,7 @@ func (exec *DataUpdateExecutor) backupData(
return nil
}
-func updateToSelect(statement, databaseName, suffix string) (string, string) {
+func updateToSelect(statement, databaseName, suffix string, issueID int) (string, string) {
// TODO(rebelice): use parser.
lowerStatement := strings.ToLower(statement)
whereIndex := strings.LastIndex(lowerStatement, "where")
@@ -170,5 +170,9 @@ func updateToSelect(statement, databaseName, suffix string) (string, string) {
tableName = strings.Trim(tableName, "`")
targetTableName := fmt.Sprintf("`%s`.`%s_%s`", databaseName, tableName, suffix)
activityTargetTableName := fmt.Sprintf("%s_%s", tableName, suffix)
- return fmt.Sprintf("CREATE TABLE %s LIKE %s; INSERT INTO %s SELECT * FROM %s %s", targetTableName, tableName, targetTableName, tableName, condition), activityTargetTableName
+ query := fmt.Sprintf("CREATE TABLE %s LIKE %s;"+
+ "ALTER TABLE %s COMMENT = 'issue %d';"+
+ "INSERT INTO %s SELECT * FROM %s %s",
+ targetTableName, tableName, targetTableName, issueID, targetTableName, tableName, condition)
+ return query, activityTargetTableName
}
diff --git a/backend/runner/taskrun/data_update_executor_test.go b/backend/runner/taskrun/data_update_executor_test.go
index 8580902a7d..da5a5dac1e 100644
--- a/backend/runner/taskrun/data_update_executor_test.go
+++ b/backend/runner/taskrun/data_update_executor_test.go
@@ -7,6 +7,6 @@ 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`.`hello_113` LIKE hello; INSERT INTO `todozp`.`hello_113` SELECT * FROM hello WHERE id > 3;", got)
+ got, _ := updateToSelect("UPDATE hello SET column1 = value1, column2 = value2 WHERE id > 3;", "todozp", "113", 355)
+ assert.Equal(t, "CREATE TABLE `todozp`.`hello_113` LIKE hello;ALTER TABLE `todozp`.`hello_113` COMMENT = 'issue 355';INSERT INTO `todozp`.`hello_113` SELECT * FROM hello WHERE id > 3;", got)
}