Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: do not parse VCS file name in task executor (#2655)
Yilong Li3ae2e56def1c
diff --git a/api/issue.go b/api/issue.goindex 77ec929703..d38366ef8e 100644--- a/api/issue.go+++ b/api/issue.go@@ -155,6 +155,9 @@ type UpdateSchemaDetail struct {Statement string `json:"statement"`// EarliestAllowedTs the earliest execution time of the change at system local Unix timestamp in seconds.EarliestAllowedTs int64 `jsonapi:"attr,earliestAllowedTs"`+ // SchemaVersion is parsed from VCS file name.+ // It is automatically generated in the UI workflow.+ SchemaVersion string `json:"schemaVersion"`}// UpdateSchemaContext is the issue create context for updating database schema.diff --git a/server/issue.go b/server/issue.goindex 99700e9d99..2abee7364e 100644--- a/server/issue.go+++ b/server/issue.go@@ -654,6 +654,10 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Conif d.Statement == "" {return nil, echo.NewHTTPError(http.StatusBadRequest, "Failed to create issue, sql statement missing")}+ // VCS push event contains schema version in the file name, which is parsed against the file template.+ if d.SchemaVersion != "" {+ schemaVersion = d.SchemaVersion+ }if d.DatabaseName == "" && d.DatabaseID > 0 {database, err := s.store.GetDatabase(ctx, &api.DatabaseFind{ID: &d.DatabaseID})@@ -743,6 +747,10 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Conreturn nil, echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", d.DatabaseID))}+ // VCS push event contains schema version in the file name, which is parsed against the file template.+ if d.SchemaVersion != "" {+ schemaVersion = d.SchemaVersion+ }taskCreate, err := getUpdateTask(database, c.MigrationType, c.VCSPushEvent, d, schemaVersion)if err != nil {return nil, errdiff --git a/server/task_executor.go b/server/task_executor.goindex ceb2a73505..4af51384ed 100644--- a/server/task_executor.go+++ b/server/task_executor.go@@ -65,6 +65,9 @@ func preMigration(ctx context.Context, server *Server, task *api.Task, migrationmi := &db.MigrationInfo{ReleaseVersion: server.profile.Version,Type: migrationType,+ // TODO(d): support semantic versioning.+ Version: schemaVersion,+ Description: task.Name,}if vcsPushEvent == nil {mi.Source = db.UI@@ -79,24 +82,9 @@ func preMigration(ctx context.Context, server *Server, task *api.Task, migration} else {mi.Creator = creator.Name}- // TODO(d): support semantic versioning.- mi.Version = schemaVersion- mi.Description = task.Name} else {- repo, err := findRepositoryByTask(ctx, server, task)- if err != nil {- return nil, err- }- mi, err = db.ParseMigrationInfo(- vcsPushEvent.FileCommit.Added,- filepath.Join(vcsPushEvent.BaseDirectory, repo.FilePathTemplate),- )- // This should not happen normally as we already check this when creating the issue. Just in case.- if err != nil {- return nil, errors.Wrap(err, "failed to prepare for database migration")- }+ mi.Source = db.VCSmi.Creator = vcsPushEvent.FileCommit.AuthorName-miPayload := &db.MigrationInfoPayload{VCSPushEvent: vcsPushEvent,}diff --git a/server/webhook.go b/server/webhook.goindex cdbfee4e31..f1333ff31d 100644--- a/server/webhook.go+++ b/server/webhook.go@@ -665,8 +665,9 @@ func (s *Server) prepareIssueFromPushEventDDL(ctx context.Context, repo *api.Repif repo.Project.TenantMode == api.TenantModeTenant {updateSchemaDetails = append(updateSchemaDetails,&api.UpdateSchemaDetail{- DatabaseName: migrationInfo.Database,- Statement: content,+ DatabaseName: migrationInfo.Database,+ Statement: content,+ SchemaVersion: migrationInfo.Version,},)} else {@@ -685,8 +686,9 @@ func (s *Server) prepareIssueFromPushEventDDL(ctx context.Context, repo *api.Repfor _, database := range databases {updateSchemaDetails = append(updateSchemaDetails,&api.UpdateSchemaDetail{- DatabaseID: database.ID,- Statement: content,+ DatabaseID: database.ID,+ Statement: content,+ SchemaVersion: migrationInfo.Version,},)}@@ -772,7 +774,7 @@ func (s *Server) createIssueFromPushEvent(ctx context.Context, pushEvent *vcs.PucreateContext, err := json.Marshal(&api.UpdateSchemaContext{- MigrationType: db.Migrate,+ MigrationType: migrationInfo.Type,VCSPushEvent: pushEvent,DetailList: updateSchemaDetails,},