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: verbose logging for VCS workflow and schema migration (#1386)
tianzhou6046019741da
diff --git a/server/task_executor.go b/server/task_executor.goindex 96d7af67ed..efc4ddb308 100644--- a/server/task_executor.go+++ b/server/task_executor.go@@ -131,7 +131,7 @@ func executeMigration(ctx context.Context, l *zap.Logger, task *api.Task, statem}defer driver.Close(ctx)- l.Debug("Start sql migration...",+ l.Debug("Start migration...",zap.String("instance", task.Instance.Name),zap.String("database", databaseName),zap.String("source", mi.Source.String()),@@ -191,6 +191,12 @@ func postMigration(ctx context.Context, l *zap.Logger, server *Server, task *api}}+ l.Debug("Post migration...",+ zap.String("instance", task.Instance.Name),+ zap.String("database", databaseName),+ zap.Bool("writeBack", writeBack),+ )+if writeBack {dbName, err := api.GetBaseDatabaseName(mi.Database, project.DBNameTemplate, task.Database.Labels)if err != nil {@@ -368,6 +374,10 @@ func writeBackLatestSchema(ctx context.Context, server *Server, repository *api.Content: schema,}if createSchemaFile {+ server.l.Debug("Create latest schema file",+ zap.String("schema_file", latestSchemaFile),+ )+err := vcsPlugin.Get(vcsPlugin.GitLabSelfHost, vcsPlugin.ProviderConfig{Logger: server.l}).CreateFile(ctx,common.OauthContext{@@ -387,6 +397,10 @@ func writeBackLatestSchema(ctx context.Context, server *Server, repository *api.return "", fmt.Errorf("failed to create file after applying migration %s to %q: %w", mi.Version, mi.Database, err)}} else {+ server.l.Debug("Update latest schema file",+ zap.String("schema_file", latestSchemaFile),+ )+schemaFileCommit.LastCommitID = schemaFileMeta.LastCommitIDerr := vcsPlugin.Get(vcsPlugin.GitLabSelfHost, vcsPlugin.ProviderConfig{Logger: server.l}).OverwriteFile(ctx,diff --git a/server/webhook.go b/server/webhook.goindex 9c04289d63..c5107097dd 100644--- a/server/webhook.go+++ b/server/webhook.go@@ -67,9 +67,22 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Project mismatch, got %d, want %s", pushEvent.Project.ID, repo.ExternalID))}+ s.l.Debug("Processing gitlab webhook push event...",+ zap.String("project", repo.Project.Name),+ )+createdMessageList := []string{}for _, commit := range pushEvent.CommitList {+ s.l.Debug("Processing commit...",+ zap.String("id", commit.ID),+ zap.String("title", commit.Title),+ )+for _, added := range commit.AddedList {+ s.l.Debug("Processing added file...",+ zap.String("file", added),+ )+if !strings.HasPrefix(added, repo.BaseDirectory) {s.l.Debug("Ignored committed file, not under base directory.", zap.String("file", added), zap.String("base_directory", repo.BaseDirectory))continue@@ -80,8 +93,9 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {s.l.Warn("Ignored committed file, failed to parse commit timestamp.", zap.String("file", added), zap.String("timestamp", commit.Timestamp), zap.Error(err))}- // Ignored the schema file we auto generated to the repository.+ // Ignore the schema file we auto generated to the repository.if isSkipGeneratedSchemaFile(repo, added, s.l) {+ s.l.Debug("Ignored generated latest schema file.", zap.String("file", added))continue}@@ -217,6 +231,13 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {}}+ if len(createdMessageList) == 0 {+ msg := "Ignored push event. No applicable file found in the commit list."+ s.l.Warn(msg,+ zap.String("project", repo.Project.Name),+ )+ return c.String(http.StatusOK, msg)+ }return c.String(http.StatusOK, strings.Join(createdMessageList, "\n"))})}@@ -318,6 +339,8 @@ func (s *Server) createTenantSchemaUpdateIssue(ctx context.Context, repository *return string(createContext), nil}+// We may write back the latest schema file to the repository after migration and we need to ignore+// this file from the webhook push event.func isSkipGeneratedSchemaFile(repository *api.Repository, added string, logger *zap.Logger) bool {if repository.SchemaPathTemplate != "" {placeholderList := []string{