MCPcopy Create free account
hub / github.com/bytebase/bytebase / writeCommentDiff

Function writeCommentDiff

backend/plugin/schema/pg/metadata_migration.go:1419–1452  ·  view source on GitHub ↗
(out *strings.Builder, commentDiff *schema.CommentDiff)

Source from the content-addressed store, hash-verified

1417}
1418
1419func writeCommentDiff(out *strings.Builder, commentDiff *schema.CommentDiff) error {
1420 switch commentDiff.ObjectType {
1421 case schema.CommentObjectTypeSchema:
1422 return writeComment(out, fmt.Sprintf("SCHEMA \"%s\"", commentDiff.ObjectName), commentDiff.NewComment)
1423 case schema.CommentObjectTypeTable:
1424 return writeComment(out, fmt.Sprintf("TABLE \"%s\".\"%s\"", commentDiff.SchemaName, commentDiff.ObjectName), commentDiff.NewComment)
1425 case schema.CommentObjectTypeColumn:
1426 return writeComment(out, fmt.Sprintf("COLUMN \"%s\".\"%s\".\"%s\"", commentDiff.SchemaName, commentDiff.ObjectName, commentDiff.ColumnName), commentDiff.NewComment)
1427 case schema.CommentObjectTypeView:
1428 return writeComment(out, fmt.Sprintf(viewCommentObjectFormat, commentDiff.SchemaName, commentDiff.ObjectName), commentDiff.NewComment)
1429 case schema.CommentObjectTypeMaterializedView:
1430 return writeComment(out, fmt.Sprintf("MATERIALIZED VIEW \"%s\".\"%s\"", commentDiff.SchemaName, commentDiff.ObjectName), commentDiff.NewComment)
1431 case schema.CommentObjectTypeFunction:
1432 return writeComment(out, fmt.Sprintf("FUNCTION %s", formatQualifiedRoutineSignature(commentDiff.SchemaName, commentDiff.ObjectName)), commentDiff.NewComment)
1433 case schema.CommentObjectTypeSequence:
1434 return writeComment(out, fmt.Sprintf("SEQUENCE \"%s\".\"%s\"", commentDiff.SchemaName, commentDiff.ObjectName), commentDiff.NewComment)
1435 case schema.CommentObjectTypeIndex:
1436 indexName := commentDiff.IndexName
1437 if indexName == "" {
1438 indexName = commentDiff.ObjectName
1439 }
1440 return writeComment(out, fmt.Sprintf("INDEX \"%s\".\"%s\"", commentDiff.SchemaName, indexName), commentDiff.NewComment)
1441 case schema.CommentObjectTypeTrigger:
1442 return writeComment(out, fmt.Sprintf("TRIGGER \"%s\" ON \"%s\".\"%s\"", commentDiff.ObjectName, commentDiff.SchemaName, commentDiff.TableName), commentDiff.NewComment)
1443 case schema.CommentObjectTypeType:
1444 return writeComment(out, fmt.Sprintf("TYPE \"%s\".\"%s\"", commentDiff.SchemaName, commentDiff.ObjectName), commentDiff.NewComment)
1445 case schema.CommentObjectTypeExtension:
1446 return writeComment(out, fmt.Sprintf("EXTENSION \"%s\"", commentDiff.ObjectName), commentDiff.NewComment)
1447 case schema.CommentObjectTypeEventTrigger:
1448 return writeComment(out, fmt.Sprintf("EVENT TRIGGER \"%s\"", commentDiff.ObjectName), commentDiff.NewComment)
1449 default:
1450 return nil
1451 }
1452}
1453
1454func writeComment(out io.Writer, object, comment string) error {
1455 if comment == "" {

Callers 1

writeCommentChangesFunction · 0.85

Calls 2

writeCommentFunction · 0.85

Tested by

no test coverage detected