Skip to content

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

chore: revert PR #2614 (#2650)

Yilong Libb1f1e3bdbe1
diff --git a/api/issue.go b/api/issue.go
index 417cfa960b..77ec929703 100644
--- a/api/issue.go
+++ b/api/issue.go
@@ -157,7 +157,7 @@ type UpdateSchemaDetail struct {
EarliestAllowedTs int64 `jsonapi:"attr,earliestAllowedTs"`
}
-// UpdateSchemaContext is the shared issue create context for updating database schema and data.
+// UpdateSchemaContext is the issue create context for updating database schema.
type UpdateSchemaContext struct {
// MigrationType is the type of a migration.
MigrationType db.MigrationType `json:"migrationType"`
@@ -166,9 +166,6 @@ type UpdateSchemaContext struct {
DetailList []*UpdateSchemaDetail `json:"updateSchemaDetailList"`
// VCSPushEvent is the event information for VCS push.
VCSPushEvent *vcs.PushEvent `json:"vcsPushEvent"`
- // MigrationInfo is only available when VCSPushEvent != nil.
- // It's parsed from VCSPushEvent.
- MigrationInfo *db.MigrationInfo `json:"migrationInfo,omitempty"`
}
// UpdateSchemaGhostDetail is the detail of updating database schema using gh-ost.
diff --git a/api/task.go b/api/task.go
index 027f682c49..e1856461ed 100644
--- a/api/task.go
+++ b/api/task.go
@@ -99,9 +99,6 @@ type TaskDatabaseSchemaUpdatePayload struct {
Statement string `json:"statement,omitempty"`
SchemaVersion string `json:"schemaVersion,omitempty"`
VCSPushEvent *vcs.PushEvent `json:"pushEvent,omitempty"`
- // MigrationInfo is only available when VCSPushEvent != nil.
- // It's parsed from VCSPushEvent.
- MigrationInfo *db.MigrationInfo `json:"migrationInfo,omitempty"`
}
// TaskDatabaseSchemaUpdateGhostSyncPayload is the task payload for gh-ost syncing ghost table.
@@ -124,9 +121,6 @@ type TaskDatabaseDataUpdatePayload struct {
Statement string `json:"statement,omitempty"`
SchemaVersion string `json:"schemaVersion,omitempty"`
VCSPushEvent *vcs.PushEvent `json:"pushEvent,omitempty"`
- // MigrationInfo is only available when VCSPushEvent != nil.
- // It's parsed from VCSPushEvent.
- MigrationInfo *db.MigrationInfo `json:"migrationInfo,omitempty"`
}
// TaskDatabaseBackupPayload is the task payload for database backup.
diff --git a/server/issue.go b/server/issue.go
index 8df479b17d..99700e9d99 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -639,10 +639,6 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Con
}
schemaVersion := common.DefaultMigrationVersion()
- // VCS push event contains the migration version in the file path.
- if c.MigrationInfo != nil {
- schemaVersion = c.MigrationInfo.Version
- }
// Tenant mode project pipeline has its own generation.
if project.TenantMode == api.TenantModeTenant {
if !s.feature(api.FeatureMultiTenancy) {
@@ -668,7 +664,7 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Con
return nil, echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", d.DatabaseID))
}
- taskCreate, err := getUpdateTask(database, c, d, schemaVersion)
+ taskCreate, err := getUpdateTask(database, c.MigrationType, c.VCSPushEvent, d, schemaVersion)
if err != nil {
return nil, err
}
@@ -701,7 +697,7 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Con
environmentSet[database.Instance.Environment.Name] = true
environmentID = database.Instance.EnvironmentID
- taskCreate, err := getUpdateTask(database, c, d, schemaVersion)
+ taskCreate, err := getUpdateTask(database, c.MigrationType, c.VCSPushEvent, d, schemaVersion)
if err != nil {
return nil, err
}
@@ -747,7 +743,7 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Con
return nil, echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", d.DatabaseID))
}
- taskCreate, err := getUpdateTask(database, c, d, schemaVersion)
+ taskCreate, err := getUpdateTask(database, c.MigrationType, c.VCSPushEvent, d, schemaVersion)
if err != nil {
return nil, err
}
@@ -829,33 +825,32 @@ func (s *Server) getPipelineCreateForDatabaseSchemaUpdateGhost(ctx context.Conte
return create, nil
}
-func getUpdateTask(database *api.Database, c api.UpdateSchemaContext, d *api.UpdateSchemaDetail, schemaVersion string) (*api.TaskCreate, error) {
+func getUpdateTask(database *api.Database, migrationType db.MigrationType, vcsPushEvent *vcs.PushEvent, d *api.UpdateSchemaDetail, schemaVersion string) (*api.TaskCreate, error) {
taskName := fmt.Sprintf("Establish %q baseline", database.Name)
- switch c.MigrationType {
+ switch migrationType {
case db.Migrate:
taskName = fmt.Sprintf("Update %q schema", database.Name)
case db.Data:
taskName = fmt.Sprintf("Update %q data", database.Name)
}
payload := api.TaskDatabaseSchemaUpdatePayload{}
- payload.MigrationType = c.MigrationType
+ payload.MigrationType = migrationType
payload.Statement = d.Statement
payload.SchemaVersion = schemaVersion
- if c.VCSPushEvent != nil {
- payload.VCSPushEvent = c.VCSPushEvent
- payload.MigrationInfo = c.MigrationInfo
+ if vcsPushEvent != nil {
+ payload.VCSPushEvent = vcsPushEvent
}
bytes, err := json.Marshal(payload)
if err != nil {
errMsg := fmt.Sprintf("Failed to marshal database schema update payload: %v", err)
- if c.MigrationType == db.Data {
+ if migrationType == db.Data {
errMsg = fmt.Sprintf("Failed to marshal database data update payload: %v", err)
}
return nil, echo.NewHTTPError(http.StatusInternalServerError, errMsg)
}
taskType := api.TaskDatabaseSchemaUpdate
- if c.MigrationType == db.Data {
+ if migrationType == db.Data {
taskType = api.TaskDatabaseDataUpdate
}
return &api.TaskCreate{
@@ -866,7 +861,7 @@ func getUpdateTask(database *api.Database, c api.UpdateSchemaContext, d *api.Upd
Type: taskType,
Statement: d.Statement,
EarliestAllowedTs: d.EarliestAllowedTs,
- MigrationType: c.MigrationType,
+ MigrationType: migrationType,
Payload: string(bytes),
}, nil
}
diff --git a/server/task_executor.go b/server/task_executor.go
index 805720e1c1..ceb2a73505 100644
--- a/server/task_executor.go
+++ b/server/task_executor.go
@@ -52,7 +52,7 @@ func RunTaskExecutorOnce(ctx context.Context, exec TaskExecutor, server *Server,
return exec.RunOnce(ctx, server, task)
}
-func preMigration(ctx context.Context, server *Server, task *api.Task, migrationType db.MigrationType, statement, schemaVersion string, vcsPushEvent *vcsPlugin.PushEvent, mi *db.MigrationInfo) (*db.MigrationInfo, error) {
+func preMigration(ctx context.Context, server *Server, task *api.Task, migrationType db.MigrationType, statement, schemaVersion string, vcsPushEvent *vcsPlugin.PushEvent) (*db.MigrationInfo, error) {
if task.Database == nil {
msg := "missing database when updating schema"
if migrationType == db.Data {
@@ -62,11 +62,11 @@ func preMigration(ctx context.Context, server *Server, task *api.Task, migration
}
databaseName := task.Database.Name
+ mi := &db.MigrationInfo{
+ ReleaseVersion: server.profile.Version,
+ Type: migrationType,
+ }
if vcsPushEvent == nil {
- mi = &db.MigrationInfo{
- ReleaseVersion: server.profile.Version,
- Type: migrationType,
- }
mi.Source = db.UI
creator, err := server.store.GetPrincipalByID(ctx, task.CreatorID)
if err != nil {
@@ -82,8 +82,7 @@ func preMigration(ctx context.Context, server *Server, task *api.Task, migration
// TODO(d): support semantic versioning.
mi.Version = schemaVersion
mi.Description = task.Name
- } else if mi == nil {
- // TODO(dragonly): remove this branch when old task without MigrationInfo is rare.
+ } else {
repo, err := findRepositoryByTask(ctx, server, task)
if err != nil {
return nil, err
@@ -301,8 +300,8 @@ func postMigration(ctx context.Context, server *Server, task *api.Task, vcsPushE
}, nil
}
-func runMigration(ctx context.Context, server *Server, task *api.Task, migrationType db.MigrationType, statement, schemaVersion string, vcsPushEvent *vcsPlugin.PushEvent, mi *db.MigrationInfo) (bool, *api.TaskRunResultPayload, error) {
- mi, err := preMigration(ctx, server, task, migrationType, statement, schemaVersion, vcsPushEvent, mi)
+func runMigration(ctx context.Context, server *Server, task *api.Task, migrationType db.MigrationType, statement, schemaVersion string, vcsPushEvent *vcsPlugin.PushEvent) (terminated bool, result *api.TaskRunResultPayload, err error) {
+ mi, err := preMigration(ctx, server, task, migrationType, statement, schemaVersion, vcsPushEvent)
if err != nil {
return true, nil, err
}
diff --git a/server/task_executor_data_update.go b/server/task_executor_data_update.go
index 9674bdc4de..4e4e4995db 100644
--- a/server/task_executor_data_update.go
+++ b/server/task_executor_data_update.go
@@ -28,7 +28,7 @@ func (*DataUpdateTaskExecutor) RunOnce(ctx context.Context, server *Server, task
return true, nil, errors.Wrap(err, "invalid database data update payload")
}
- return runMigration(ctx, server, task, db.Data, payload.Statement, payload.SchemaVersion, payload.VCSPushEvent, payload.MigrationInfo)
+ return runMigration(ctx, server, task, db.Data, payload.Statement, payload.SchemaVersion, payload.VCSPushEvent)
}
// IsCompleted tells the scheduler if the task execution has completed.
diff --git a/server/task_executor_schema_update.go b/server/task_executor_schema_update.go
index f7bc107474..c18694f4b7 100644
--- a/server/task_executor_schema_update.go
+++ b/server/task_executor_schema_update.go
@@ -8,7 +8,6 @@ import (
"github.com/pkg/errors"
"github.com/bytebase/bytebase/api"
- "github.com/bytebase/bytebase/plugin/db"
)
// NewSchemaUpdateTaskExecutor creates a schema update (DDL) task executor.
@@ -29,7 +28,7 @@ func (exec *SchemaUpdateTaskExecutor) RunOnce(ctx context.Context, server *Serve
return true, nil, errors.Wrap(err, "invalid database schema update payload")
}
- return runMigration(ctx, server, task, db.Migrate, payload.Statement, payload.SchemaVersion, payload.VCSPushEvent, payload.MigrationInfo)
+ return runMigration(ctx, server, task, payload.MigrationType, payload.Statement, payload.SchemaVersion, payload.VCSPushEvent)
}
// IsCompleted tells the scheduler if the task execution has completed.
diff --git a/server/task_executor_schema_update_ghost_cutover.go b/server/task_executor_schema_update_ghost_cutover.go
index cbe22d7123..1f77f009d0 100644
--- a/server/task_executor_schema_update_ghost_cutover.go
+++ b/server/task_executor_schema_update_ghost_cutover.go
@@ -18,6 +18,7 @@ import (
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db"
"github.com/bytebase/bytebase/plugin/db/util"
+ vcsPlugin "github.com/bytebase/bytebase/plugin/vcs"
)
// NewSchemaUpdateGhostCutoverTaskExecutor creates a schema update (gh-ost) cutover task executor.
@@ -64,13 +65,13 @@ func (exec *SchemaUpdateGhostCutoverTaskExecutor) RunOnce(ctx context.Context, s
}
sharedGhost := value.(sharedGhostState)
- return cutover(ctx, server, task, payload, postponeFilename, sharedGhost.migrationContext, sharedGhost.errCh)
+ return cutover(ctx, server, task, payload.Statement, payload.SchemaVersion, payload.VCSPushEvent, postponeFilename, sharedGhost.migrationContext, sharedGhost.errCh)
}
-func cutover(ctx context.Context, server *Server, task *api.Task, payload *api.TaskDatabaseSchemaUpdateGhostSyncPayload, postponeFilename string, migrationContext *base.MigrationContext, errCh <-chan error) (terminated bool, result *api.TaskRunResultPayload, err error) {
- statement := strings.TrimSpace(payload.Statement)
+func cutover(ctx context.Context, server *Server, task *api.Task, statement, schemaVersion string, vcsPushEvent *vcsPlugin.PushEvent, postponeFilename string, migrationContext *base.MigrationContext, errCh <-chan error) (terminated bool, result *api.TaskRunResultPayload, err error) {
+ statement = strings.TrimSpace(statement)
- mi, err := preMigration(ctx, server, task, db.Migrate, statement, payload.SchemaVersion, payload.VCSPushEvent, nil)
+ mi, err := preMigration(ctx, server, task, db.Migrate, statement, schemaVersion, vcsPushEvent)
if err != nil {
return true, nil, err
}
@@ -139,7 +140,7 @@ func cutover(ctx context.Context, server *Server, task *api.Task, payload *api.T
return true, nil, err
}
- return postMigration(ctx, server, task, payload.VCSPushEvent, mi, migrationID, schema)
+ return postMigration(ctx, server, task, vcsPushEvent, mi, migrationID, schema)
}
func waitForCutover(ctx context.Context, migrationContext *base.MigrationContext) bool {
diff --git a/server/webhook.go b/server/webhook.go
index 63620a5cfc..cdbfee4e31 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -649,22 +649,6 @@ func (s *Server) prepareIssueFromPushEventDDL(ctx context.Context, repo *api.Rep
return nil
}
- migrationInfo.Creator = pushEvent.FileCommit.AuthorName
- miPayload := &db.MigrationInfoPayload{
- VCSPushEvent: pushEvent,
- }
- bytes, err := json.Marshal(miPayload)
- if err != nil {
- log.Error("Failed to marshal vcs push event payload",
- zap.Int("project", repo.ProjectID),
- zap.Any("pushEvent", pushEvent),
- zap.String("file", file),
- zap.Error(err),
- )
- return nil
- }
- migrationInfo.Payload = string(bytes)
-
content, err := s.readFileContent(ctx, pushEvent, webhookEndpointID, file)
if err != nil {
s.createIgnoredFileActivity(
@@ -788,10 +772,9 @@ func (s *Server) createIssueFromPushEvent(ctx context.Context, pushEvent *vcs.Pu
createContext, err := json.Marshal(
&api.UpdateSchemaContext{
- MigrationType: migrationInfo.Type,
+ MigrationType: db.Migrate,
VCSPushEvent: pushEvent,
DetailList: updateSchemaDetails,
- MigrationInfo: migrationInfo,
},
)
if err != nil {