Skip to content

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

refactor: unused version (#15200)

Danny Xu55dd55e6be7c
diff --git a/backend/common/util.go b/backend/common/util.go
index 7e13ed5320..c0da421463 100644
--- a/backend/common/util.go
+++ b/backend/common/util.go
@@ -9,14 +9,12 @@ import (
"path/filepath"
"strconv"
"strings"
- "time"
"unicode/utf8"
"github.com/nyaruka/phonenumbers"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
- "github.com/bytebase/bytebase/backend/store/model"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -112,12 +110,6 @@ func GetResourceDir(dataDir string) string {
return path.Join(dataDir, "resources")
}
-// DefaultMigrationVersion returns the default migration version string.
-// Use the current time in second to guarantee uniqueness in a monotonic increasing way.
-func DefaultMigrationVersion() model.Version {
- return model.Version{Version: time.Now().Format("20060102150405")}
-}
-
// TruncateString truncates the string to have a maximum length of `limit` characters.
func TruncateString(str string, limit int) (string, bool) {
chars := 0
diff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.go
index 84d6cf7c14..ba17fdbe8b 100644
--- a/backend/runner/taskrun/data_update_executor.go
+++ b/backend/runner/taskrun/data_update_executor.go
@@ -127,8 +127,7 @@ func (exec *DataUpdateExecutor) RunOnce(ctx context.Context, driverCtx context.C
},
})
}
- version := model.Version{Version: payload.SchemaVersion}
- terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.Data, statement, version, &sheetID)
+ terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.Data, statement, payload.SchemaVersion, &sheetID)
if result != nil {
// Save prior backup detail to task run result.
result.PriorBackupDetail = priorBackupDetail
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index 7cbbb36010..d11491623a 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -19,7 +19,6 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/runner/schemasync"
"github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/store/model"
"github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -90,7 +89,7 @@ type migrateContext struct {
changelog int64
}
-func getMigrationInfo(ctx context.Context, stores *store.Store, profile *config.Profile, syncer *schemasync.Syncer, task *store.TaskMessage, migrationType db.MigrationType, statement string, schemaVersion model.Version, sheetID *int, taskRunUID int, dbFactory *dbfactory.DBFactory) (*db.MigrationInfo, *migrateContext, error) {
+func getMigrationInfo(ctx context.Context, stores *store.Store, profile *config.Profile, syncer *schemasync.Syncer, task *store.TaskMessage, migrationType db.MigrationType, statement string, schemaVersion string, sheetID *int, taskRunUID int, dbFactory *dbfactory.DBFactory) (*db.MigrationInfo, *migrateContext, error) {
instance, err := stores.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &task.InstanceID})
if err != nil {
return nil, nil, err
@@ -133,7 +132,7 @@ func getMigrationInfo(ctx context.Context, stores *store.Store, profile *config.
instance: instance,
database: database,
task: task,
- version: schemaVersion.Version,
+ version: schemaVersion,
taskRunName: common.FormatTaskRun(pipeline.ProjectID, task.PipelineID, task.StageID, task.ID, taskRunUID),
taskRunUID: taskRunUID,
}
@@ -372,7 +371,7 @@ func postMigration(ctx context.Context, stores *store.Store, mi *db.MigrationInf
}, nil
}
-func runMigration(ctx context.Context, driverCtx context.Context, store *store.Store, dbFactory *dbfactory.DBFactory, stateCfg *state.State, syncer *schemasync.Syncer, profile *config.Profile, task *store.TaskMessage, taskRunUID int, migrationType db.MigrationType, statement string, schemaVersion model.Version, sheetID *int) (terminated bool, result *storepb.TaskRunResult, err error) {
+func runMigration(ctx context.Context, driverCtx context.Context, store *store.Store, dbFactory *dbfactory.DBFactory, stateCfg *state.State, syncer *schemasync.Syncer, profile *config.Profile, task *store.TaskMessage, taskRunUID int, migrationType db.MigrationType, statement string, schemaVersion string, sheetID *int) (terminated bool, result *storepb.TaskRunResult, err error) {
mi, mc, err := getMigrationInfo(ctx, store, profile, syncer, task, migrationType, statement, schemaVersion, sheetID, taskRunUID, dbFactory)
if err != nil {
return true, nil, err
diff --git a/backend/runner/taskrun/schema_baseline_executor.go b/backend/runner/taskrun/schema_baseline_executor.go
index 1b3e3f2cca..3fffd04367 100644
--- a/backend/runner/taskrun/schema_baseline_executor.go
+++ b/backend/runner/taskrun/schema_baseline_executor.go
@@ -15,7 +15,6 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/runner/schemasync"
"github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/store/model"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -57,8 +56,7 @@ func (exec *SchemaBaselineExecutor) RunOnce(ctx context.Context, driverCtx conte
return true, nil, err
}
- version := model.Version{Version: payload.SchemaVersion}
- terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.Baseline, "" /* statement */, version, nil /* sheetID */)
+ terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.Baseline, "" /* statement */, payload.SchemaVersion, nil /* sheetID */)
if err := exec.schemaSyncer.SyncDatabaseSchema(ctx, database, false /* force */); err != nil {
slog.Error("failed to sync database schema",
slog.String("instanceName", instance.ResourceID),
diff --git a/backend/runner/taskrun/schema_update_executor.go b/backend/runner/taskrun/schema_update_executor.go
index c75778a2f5..6e87d2deab 100644
--- a/backend/runner/taskrun/schema_update_executor.go
+++ b/backend/runner/taskrun/schema_update_executor.go
@@ -16,7 +16,6 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/runner/schemasync"
"github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/store/model"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -64,8 +63,7 @@ func (exec *SchemaUpdateExecutor) RunOnce(ctx context.Context, driverCtx context
return true, nil, err
}
- version := model.Version{Version: payload.SchemaVersion}
- terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.Migrate, statement, version, &sheetID)
+ terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.Migrate, statement, payload.SchemaVersion, &sheetID)
// sync database schema anyways
exec.store.CreateTaskRunLogS(ctx, taskRunUID, time.Now(), exec.profile.DeployID, &storepb.TaskRunLog{
Type: storepb.TaskRunLog_DATABASE_SYNC_START,
diff --git a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
index 563ddc8329..dfcec084eb 100644
--- a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
@@ -21,7 +21,6 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/runner/schemasync"
"github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/store/model"
"github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -99,9 +98,7 @@ func (e *SchemaUpdateGhostCutoverExecutor) RunOnce(ctx context.Context, taskCont
return true, nil, errors.Errorf("failed to convert shared gh-ost state")
}
- // not using the rendered statement here because we want to avoid leaking the rendered statement
- version := model.Version{Version: payload.SchemaVersion}
- terminated, result, err := cutover(ctx, taskContext, e.store, e.dbFactory, e.profile, e.schemaSyncer, task, taskRunUID, statement, sheetID, version, postponeFilename, sharedGhost.migrationContext, sharedGhost.errCh)
+ terminated, result, err := cutover(ctx, taskContext, e.store, e.dbFactory, e.profile, e.schemaSyncer, task, taskRunUID, statement, sheetID, payload.SchemaVersion, postponeFilename, sharedGhost.migrationContext, sharedGhost.errCh)
if err := e.schemaSyncer.SyncDatabaseSchema(ctx, database, false /* force */); err != nil {
slog.Error("failed to sync database schema",
slog.String("instanceName", instance.ResourceID),
@@ -113,7 +110,7 @@ func (e *SchemaUpdateGhostCutoverExecutor) RunOnce(ctx context.Context, taskCont
return terminated, result, err
}
-func cutover(ctx context.Context, taskContext context.Context, stores *store.Store, dbFactory *dbfactory.DBFactory, profile *config.Profile, syncer *schemasync.Syncer, task *store.TaskMessage, taskRunUID int, statement string, sheetID int, schemaVersion model.Version, postponeFilename string, migrationContext *base.MigrationContext, errCh <-chan error) (terminated bool, result *storepb.TaskRunResult, err error) {
+func cutover(ctx context.Context, taskContext context.Context, stores *store.Store, dbFactory *dbfactory.DBFactory, profile *config.Profile, syncer *schemasync.Syncer, task *store.TaskMessage, taskRunUID int, statement string, sheetID int, schemaVersion string, postponeFilename string, migrationContext *base.MigrationContext, errCh <-chan error) (terminated bool, result *storepb.TaskRunResult, err error) {
statement = strings.TrimSpace(statement)
// wait for heartbeat lag.
// try to make the time gap between the migration history insertion and the actual cutover as close as possible.
diff --git a/backend/runner/taskrun/schema_update_sdl_executor.go b/backend/runner/taskrun/schema_update_sdl_executor.go
index 3775eb831e..8c970dedc7 100644
--- a/backend/runner/taskrun/schema_update_sdl_executor.go
+++ b/backend/runner/taskrun/schema_update_sdl_executor.go
@@ -16,7 +16,6 @@ import (
"github.com/bytebase/bytebase/backend/runner/schemasync"
"github.com/bytebase/bytebase/backend/runner/utils"
"github.com/bytebase/bytebase/backend/store"
- "github.com/bytebase/bytebase/backend/store/model"
backendutils "github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -69,12 +68,11 @@ func (exec *SchemaUpdateSDLExecutor) RunOnce(ctx context.Context, driverCtx cont
// To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.
renderedStatement := backendutils.RenderStatement(statement, materials)
- version := model.Version{Version: payload.SchemaVersion}
ddl, err := utils.ComputeDatabaseSchemaDiff(ctx, instance, database, exec.dbFactory, renderedStatement)
if err != nil {
return true, nil, errors.Wrap(err, "invalid database schema diff")
}
- terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.MigrateSDL, ddl, version, &sheetID)
+ terminated, result, err := runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, db.MigrateSDL, ddl, payload.SchemaVersion, &sheetID)
if err := exec.schemaSyncer.SyncDatabaseSchema(ctx, database, false /* force */); err != nil {
slog.Error("failed to sync database schema",