compareFunctions compares functions between two schemas.
(engine storepb.Engine, diff *MetadataDiff, schemaName string, oldSchema, newSchema *model.SchemaMetadata)
| 1644 | |
| 1645 | // compareFunctions compares functions between two schemas. |
| 1646 | func compareFunctions(engine storepb.Engine, diff *MetadataDiff, schemaName string, oldSchema, newSchema *model.SchemaMetadata) { |
| 1647 | // Get the engine-specific function comparer |
| 1648 | comparer := GetFunctionComparer(engine) |
| 1649 | |
| 1650 | // Functions can have overloading, so we need to handle them carefully |
| 1651 | // Group functions by signature to properly match overloaded functions |
| 1652 | // Build map of old functions by signature |
| 1653 | oldFuncsBySignature := make(map[string]*storepb.FunctionMetadata) |
| 1654 | for _, fn := range oldSchema.GetProto().GetFunctions() { |
| 1655 | if !fn.GetSkipDump() { |
| 1656 | sig := fn.Signature |
| 1657 | if sig == "" { |
| 1658 | sig = fn.Name // fallback if no signature |
| 1659 | } |
| 1660 | oldFuncsBySignature[sig] = fn |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | // Build map of new functions by signature |
| 1665 | newFuncsBySignature := make(map[string]*storepb.FunctionMetadata) |
| 1666 | for _, fn := range newSchema.GetProto().GetFunctions() { |
| 1667 | if !fn.GetSkipDump() { |
| 1668 | sig := fn.Signature |
| 1669 | if sig == "" { |
| 1670 | sig = fn.Name // fallback if no signature |
| 1671 | } |
| 1672 | newFuncsBySignature[sig] = fn |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | // Check for dropped functions |
| 1677 | for sig, oldFunc := range oldFuncsBySignature { |
| 1678 | if _, exists := newFuncsBySignature[sig]; !exists { |
| 1679 | // Use signature if available, otherwise fall back to name |
| 1680 | functionName := oldFunc.Signature |
| 1681 | if functionName == "" { |
| 1682 | functionName = oldFunc.Name |
| 1683 | } |
| 1684 | diff.FunctionChanges = append(diff.FunctionChanges, &FunctionDiff{ |
| 1685 | Action: MetadataDiffActionDrop, |
| 1686 | SchemaName: schemaName, |
| 1687 | FunctionName: functionName, |
| 1688 | OldFunction: oldFunc, |
| 1689 | }) |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | // Check for new and modified functions |
| 1694 | for sig, newFunc := range newFuncsBySignature { |
| 1695 | oldFunc, exists := oldFuncsBySignature[sig] |
| 1696 | if !exists { |
| 1697 | // Use signature if available, otherwise fall back to name |
| 1698 | functionName := newFunc.Signature |
| 1699 | if functionName == "" { |
| 1700 | functionName = newFunc.Name |
| 1701 | } |
| 1702 | diff.FunctionChanges = append(diff.FunctionChanges, &FunctionDiff{ |
| 1703 | Action: MetadataDiffActionCreate, |
no test coverage detected