compareColumns compares columns between two tables.
(engine storepb.Engine, oldTable, newTable *model.TableMetadata)
| 598 | |
| 599 | // compareColumns compares columns between two tables. |
| 600 | func 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. |
| 640 | func columnsEqual(engine storepb.Engine, col1, col2 *storepb.ColumnMetadata) bool { |
no test coverage detected