Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: no dump/sync for dml (#13115)
p0nyfce77cf6e059
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.goindex 9658ee8dea..8023710834 100644--- a/backend/plugin/db/driver.go+++ b/backend/plugin/db/driver.go@@ -124,6 +124,15 @@ func (t MigrationType) GetVersionTypeSuffix() string {return ""}+func (t MigrationType) NeedDump() bool {+ switch t {+ case Baseline, Migrate, MigrateSDL:+ return true+ default:+ return false+ }+}+// MigrationStatus is the status of migration.type MigrationStatus stringdiff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.goindex b88e877e6c..4c9ab0c99f 100644--- a/backend/runner/taskrun/data_update_executor.go+++ b/backend/runner/taskrun/data_update_executor.go@@ -62,15 +62,6 @@ func (exec *DataUpdateExecutor) RunOnce(ctx context.Context, driverCtx context.Creturn true, nil, errors.Wrap(err, "invalid database data update payload")}- instance, err := exec.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})- if err != nil {- return true, nil, err- }- database, err := exec.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: task.DatabaseID})- if err != nil {- return true, nil, err- }-sheetID := int(payload.SheetId)statement, err := exec.store.GetSheetStatementByID(ctx, sheetID)if err != nil {@@ -86,30 +77,6 @@ func (exec *DataUpdateExecutor) RunOnce(ctx context.Context, driverCtx context.C// Save prior backup detail to task run result.result.PriorBackupDetail = priorBackupDetail}- // sync database schema anyways- exec.store.CreateTaskRunLogS(ctx, taskRunUID, time.Now(), exec.profile.DeployID, &storepb.TaskRunLog{- Type: storepb.TaskRunLog_DATABASE_SYNC_START,- DatabaseSyncStart: &storepb.TaskRunLog_DatabaseSyncStart{},- })- if err := exec.schemaSyncer.SyncDatabaseSchema(ctx, database, false /* force */); err != nil {- exec.store.CreateTaskRunLogS(ctx, taskRunUID, time.Now(), exec.profile.DeployID, &storepb.TaskRunLog{- Type: storepb.TaskRunLog_DATABASE_SYNC_END,- DatabaseSyncEnd: &storepb.TaskRunLog_DatabaseSyncEnd{- Error: err.Error(),- },- })- slog.Error("failed to sync database schema",- slog.String("instanceName", instance.ResourceID),- slog.String("databaseName", database.DatabaseName),- log.BBError(err),- )- }- exec.store.CreateTaskRunLogS(ctx, taskRunUID, time.Now(), exec.profile.DeployID, &storepb.TaskRunLog{- Type: storepb.TaskRunLog_DATABASE_SYNC_END,- DatabaseSyncEnd: &storepb.TaskRunLog_DatabaseSyncEnd{- Error: "",- },- })return terminated, result, err}diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.goindex ddecfc0235..7e6949e053 100644--- a/backend/tests/schema_update_test.go+++ b/backend/tests/schema_update_test.go@@ -104,8 +104,8 @@ func TestSchemaAndDataUpdate(t *testing.T) {Source: v1pb.ChangeHistory_UI,Type: v1pb.ChangeHistory_DATA,Status: v1pb.ChangeHistory_DONE,- Schema: dumpedSchema,- PrevSchema: dumpedSchema,+ Schema: "",+ PrevSchema: "",},{Source: v1pb.ChangeHistory_UI,diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex e54c18f273..bacde903fd 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -247,16 +247,18 @@ func ExecuteMigrationDefault(ctx context.Context, driverCtx context.Context, sto// ExecuteMigrationWithFunc executes the migration with custom migration function.func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, s *store.Store, stateCfg *state.State, taskRunUID int, driver db.Driver, m *db.MigrationInfo, statement string, sheetID *int, execFunc func(ctx context.Context, execStatement string) error, opts db.ExecuteOptions) (migrationHistoryID string, updatedSchema string, resErr error) {- opts.LogSchemaDumpStart()var prevSchemaBuf bytes.Buffer- // Don't record schema if the database hasn't existed yet or is schemaless, e.g. MongoDB.- // For baseline migration, we also record the live schema to detect the schema drift.- // See https://bytebase.com/blog/what-is-database-schema-drift- if _, err := driver.Dump(ctx, &prevSchemaBuf); err != nil {- opts.LogSchemaDumpEnd(err.Error())- return "", "", err+ if m.Type.NeedDump() {+ opts.LogSchemaDumpStart()+ // Don't record schema if the database hasn't existed yet or is schemaless, e.g. MongoDB.+ // For baseline migration, we also record the live schema to detect the schema drift.+ // See https://bytebase.com/blog/what-is-database-schema-drift+ if _, err := driver.Dump(ctx, &prevSchemaBuf); err != nil {+ opts.LogSchemaDumpEnd(err.Error())+ return "", "", err+ }+ opts.LogSchemaDumpEnd("")}- opts.LogSchemaDumpEnd("")insertedID, err := BeginMigration(ctx, s, m, prevSchemaBuf.String(), statement, sheetID)if err != nil {@@ -321,18 +323,20 @@ func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, s})}- opts.LogSchemaDumpStart()// Phase 4 - Dump the schema after migrationvar afterSchemaBuf bytes.Buffer- if _, err := driver.Dump(ctx, &afterSchemaBuf); err != nil {- // We will ignore the dump error if the database is dropped.- if strings.Contains(err.Error(), "not found") {- return insertedID, "", nil+ if m.Type.NeedDump() {+ opts.LogSchemaDumpStart()+ if _, err := driver.Dump(ctx, &afterSchemaBuf); err != nil {+ // We will ignore the dump error if the database is dropped.+ if strings.Contains(err.Error(), "not found") {+ return insertedID, "", nil+ }+ opts.LogSchemaDumpEnd(err.Error())+ return "", "", err}- opts.LogSchemaDumpEnd(err.Error())- return "", "", err+ opts.LogSchemaDumpEnd("")}- opts.LogSchemaDumpEnd("")return insertedID, afterSchemaBuf.String(), nil}