Skip to content

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

refactor: deprecate begin func (#12441)

h3n4l3ca82b04f314
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index 0c84037bd1..cee8342983 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -141,23 +141,6 @@ type TaskDatabaseDataUpdatePayload struct {
SheetID int `json:"sheetId,omitempty"`
SchemaVersion string `json:"schemaVersion,omitempty"`
- // MySQL rollback SQL related.
-
- // TransactionID is the ID of the transaction executing the migration.
- // It is only use for Oracle to find Rollback SQL statement now.
- TransactionID string `json:"transactionId,omitempty"`
- // ThreadID is the ID of the connection executing the migration.
- // We use it to filter the binlog events of the migration transaction.
- ThreadID string `json:"threadId,omitempty"`
- // MigrationID is the ID of the migration history record.
- // We use it to get the schema when the transaction ran.
- MigrationID string `json:"migrationId,omitempty"`
- // BinlogXxx are obtained before and after executing the migration.
- // We use them to locate the range of binlog for the migration transaction.
- BinlogFileStart string `json:"binlogFileStart,omitempty"`
- BinlogFileEnd string `json:"binlogFileEnd,omitempty"`
- BinlogPosStart int64 `json:"binlogPosStart,omitempty"`
- BinlogPosEnd int64 `json:"binlogPosEnd,omitempty"`
PreUpdateBackupDetail PreUpdateBackupDetail `json:"preUpdateBackupDetail,omitempty"`
}
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.go
index 1049d88644..78a8f8a43e 100644
--- a/backend/plugin/db/driver.go
+++ b/backend/plugin/db/driver.go
@@ -353,7 +353,6 @@ func Open(ctx context.Context, dbType storepb.Engine, driverConfig DriverConfig,
// ExecuteOptions is the options for execute.
type ExecuteOptions struct {
CreateDatabase bool
- BeginFunc func(ctx context.Context, conn *sql.Conn) error
UpdateExecutionStatus func(*v1pb.TaskRun_ExecutionDetail)
CreateTaskRunLog func(time.Time, *storepb.TaskRunLog) error
}
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.go
index e47c3bd844..4faf2ed65d 100644
--- a/backend/plugin/db/mysql/mysql.go
+++ b/backend/plugin/db/mysql/mysql.go
@@ -308,12 +308,6 @@ func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteO
}
slog.Debug("connectionID", slog.String("connectionID", connectionID))
- if opts.BeginFunc != nil {
- if err := opts.BeginFunc(ctx, conn); err != nil {
- return 0, err
- }
- }
-
var totalCommands int
var commands []base.SingleSQL
var originalIndex []int
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index 2370a133b7..94e464b2ff 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -2,8 +2,6 @@ package taskrun
import (
"context"
- "database/sql"
- "encoding/json"
"fmt"
"log/slog"
"sort"
@@ -19,7 +17,6 @@ import (
"github.com/bytebase/bytebase/backend/component/state"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/db"
- "github.com/bytebase/bytebase/backend/plugin/db/mysql"
"github.com/bytebase/bytebase/backend/store"
"github.com/bytebase/bytebase/backend/store/model"
"github.com/bytebase/bytebase/backend/utils"
@@ -220,16 +217,6 @@ func executeMigration(
var migrationID string
opts := db.ExecuteOptions{}
- if task.Type == api.TaskDatabaseDataUpdate && (instance.Engine == storepb.Engine_MYSQL || instance.Engine == storepb.Engine_MARIADB) {
- opts.BeginFunc = func(ctx context.Context, conn *sql.Conn) error {
- updatedTask, err := setThreadIDAndStartBinlogCoordinate(ctx, conn, task, stores)
- if err != nil {
- return errors.Wrap(err, "failed to update the task payload for MySQL rollback SQL")
- }
- task = updatedTask
- return nil
- }
- }
if profile.ExecuteDetail && stateCfg != nil {
switch task.Type {
@@ -263,46 +250,6 @@ func executeMigration(
return migrationID, schema, nil
}
-func setThreadIDAndStartBinlogCoordinate(ctx context.Context, conn *sql.Conn, task *store.TaskMessage, store *store.Store) (*store.TaskMessage, error) {
- payload := &api.TaskDatabaseDataUpdatePayload{}
- if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
- return nil, errors.Wrap(err, "invalid database data update payload")
- }
-
- var connID string
- if err := conn.QueryRowContext(ctx, "SELECT CONNECTION_ID();").Scan(&connID); err != nil {
- return nil, errors.Wrap(err, "failed to get the connection ID")
- }
- payload.ThreadID = connID
-
- binlogInfo, err := mysql.GetBinlogInfo(ctx, conn)
- if err != nil {
- return nil, errors.Wrap(err, "failed to get the binlog info before executing the migration transaction")
- }
- if (binlogInfo == api.BinlogInfo{}) {
- slog.Warn("binlog is not enabled", slog.Int("task", task.ID))
- return task, nil
- }
- payload.BinlogFileStart = binlogInfo.FileName
- payload.BinlogPosStart = binlogInfo.Position
-
- payloadBytes, err := json.Marshal(payload)
- if err != nil {
- return nil, errors.Wrap(err, "failed to marshal task payload")
- }
- payloadString := string(payloadBytes)
- patch := &api.TaskPatch{
- ID: task.ID,
- UpdaterID: api.SystemBotID,
- Payload: &payloadString,
- }
- updatedTask, err := store.UpdateTaskV2(ctx, patch)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to patch task %d with the MySQL thread ID", task.ID)
- }
- return updatedTask, nil
-}
-
func postMigration(ctx context.Context, stores *store.Store, task *store.TaskMessage, mi *db.MigrationInfo, migrationID string, sheetID *int) (bool, *storepb.TaskRunResult, error) {
instance, err := stores.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})
if err != nil {