MCPcopy Index your code
hub / github.com/bytebase/bytebase / compareColumns

Function compareColumns

backend/plugin/schema/differ.go:600–637  ·  view source on GitHub ↗

compareColumns compares columns between two tables.

(engine storepb.Engine, oldTable, newTable *model.TableMetadata)

Source from the content-addressed store, hash-verified

598
599// compareColumns compares columns between two tables.
600func compareColumns(engine storepb.Engine, oldTable, newTable *model.TableMetadata) []*ColumnDiff {
601 var changes []*ColumnDiff
602
603 oldColumns := oldTable.GetProto().GetColumns()
604 newColumns := newTable.GetProto().GetColumns()
605
606 // Check for dropped columns
607 for _, oldCol := range oldColumns {
608 if newTable.GetColumn(oldCol.Name) == nil {
609 changes = append(changes, &ColumnDiff{
610 Action: MetadataDiffActionDrop,
611 OldColumn: oldCol,
612 })
613 }
614 }
615
616 // Check for new and modified columns
617 for _, newCol := range newColumns {
618 oldColWrapper := oldTable.GetColumn(newCol.Name)
619 if oldColWrapper == nil {
620 changes = append(changes, &ColumnDiff{
621 Action: MetadataDiffActionCreate,
622 NewColumn: newCol,
623 })
624 } else {
625 oldCol := oldColWrapper.GetProto()
626 if !columnsEqual(engine, oldCol, newCol) {
627 changes = append(changes, &ColumnDiff{
628 Action: MetadataDiffActionAlter,
629 OldColumn: oldCol,
630 NewColumn: newCol,
631 })
632 }
633 }
634 }
635
636 return changes
637}
638
639// columnsEqual checks if two columns are equal.
640func columnsEqual(engine storepb.Engine, col1, col2 *storepb.ColumnMetadata) bool {

Callers 1

compareTableDetailsFunction · 0.70

Calls 4

columnsEqualFunction · 0.85
GetColumnsMethod · 0.45
GetProtoMethod · 0.45
GetColumnMethod · 0.45

Tested by

no test coverage detected