Skip to content

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

fix: sanitize user comment for manually rebased result (#12156)

h3n4l0b6bcedd35b2
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index 14dc7a8843..7ff081da8e 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -555,7 +555,11 @@ func (s *BranchService) RebaseBranch(ctx context.Context, request *v1pb.RebaseBr
return nil, status.Errorf(codes.InvalidArgument, "failed to convert merged schema to metadata, %v", err)
}
newHeadConfig = baseBranch.Head.GetDatabaseConfig()
- sanitizeCommentForSchemaMetadata(newHeadMetadata, model.NewDatabaseConfig(newHeadConfig))
+ // String-based rebase operation do not include the structural information, such as classification, so we need to sanitize the user comment,
+ // trim the classification in user comment if the classification is not from the config.
+ modelNewHeadConfig := model.NewDatabaseConfig(newHeadConfig)
+ trimClassificationIDFromCommentIfNeeded(newHeadMetadata, modelNewHeadConfig)
+ sanitizeCommentForSchemaMetadata(newHeadMetadata, modelNewHeadConfig)
reconcileMetadata(newHeadMetadata, baseBranch.Engine)
} else {
newHeadMetadata, err = tryMerge(baseBranch.Base.Metadata, baseBranch.Head.Metadata, filteredNewBaseMetadata)
@@ -1571,3 +1575,21 @@ func initializeBranchUpdaterInfoConfig(metadata *storepb.DatabaseSchemaMetadata,
}
}
}
+
+func trimClassificationIDFromCommentIfNeeded(dbSchema *storepb.DatabaseSchemaMetadata, dbModelConfig *model.DatabaseConfig) {
+ if dbModelConfig.ClassificationFromConfig {
+ return
+ }
+ for _, schema := range dbSchema.Schemas {
+ for _, table := range schema.Tables {
+ if !dbModelConfig.ClassificationFromConfig {
+ _, table.UserComment = common.GetClassificationAndUserComment(table.UserComment)
+ }
+ for _, col := range table.Columns {
+ if !dbModelConfig.ClassificationFromConfig {
+ _, col.UserComment = common.GetClassificationAndUserComment(col.UserComment)
+ }
+ }
+ }
+ }
+}