--- a/pgtoolkit/pgdiff.py Thu Jan 24 17:11:17 2013 +0100
+++ b/pgtoolkit/pgdiff.py Fri Jan 25 17:06:54 2013 +0100
@@ -118,6 +118,18 @@
self.name = table
+class DiffArgument(DiffBase):
+ def __init__(self, change, schema, function, argument):
+ DiffBase.__init__(self)
+ self.level = 2
+ self.type = 'argument'
+ self.change = change
+ self.schema = schema
+ self.function = function
+ self.argument = argument
+ self.name = argument
+
+
class DiffFunction(DiffBase):
def __init__(self, change, schema, function):
DiffBase.__init__(self)
@@ -247,16 +259,6 @@
if x not in src:
yield ('+', x)
- def _compare_functions(self, a, b):
- diff = []
- if a.arguments != b.arguments:
- diff.append(('args', a.arguments, b.arguments))
- if a.result != b.result:
- diff.append(('result', a.result, b.result))
- if a.source != b.source:
- diff.append(('source', a.source, b.source))
- return diff
-
def _compare_columns(self, a, b):
diff = []
if a.type != b.type:
@@ -275,6 +277,24 @@
diff.append(('definition', a.definition, b.definition))
return diff
+ def _compare_functions(self, a, b):
+ diff = []
+ if a.result != b.result:
+ diff.append(('result', a.result, b.result))
+ if a.source != b.source:
+ diff.append(('source', a.source, b.source))
+ return diff
+
+ def _compare_arguments(self, a, b):
+ diff = []
+ if a.type != b.type:
+ diff.append(('type', a.type, b.type))
+ if a.mode != b.mode:
+ diff.append(('mode', a.mode, b.mode))
+ if a.default != b.default:
+ diff.append(('default', a.default, b.default))
+ return diff
+
def _diff_columns(self, schema, table, src_columns, dst_columns):
for nd in self._diff_names(src_columns, dst_columns):
if nd[1] in dst_columns:
@@ -336,16 +356,37 @@
else:
yield tdo
+ def _diff_arguments(self, schema, function, src_args, dst_args):
+ for nd in self._diff_names(src_args, dst_args):
+ ado = DiffArgument(change=nd[0], schema=schema, function=function, argument=nd[1])
+ if nd[0] == '*':
+ a = src_args[nd[1]]
+ b = dst_args[nd[1]]
+ ado.changes = self._compare_arguments(a, b)
+ if ado.changes:
+ yield ado
+ else:
+ yield ado
+
def _diff_functions(self, schema, src_functions, dst_functions):
for nd in self._diff_names(src_functions, dst_functions):
fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1])
if nd[0] == '*':
- # compare function body and arguments
+ # compare function body and result
a = src_functions[nd[1]]
b = dst_functions[nd[1]]
fdo.changes = self._compare_functions(a, b)
if fdo.changes:
yield fdo
+ fdo = None
+ # arguments
+ src_args = src_functions[nd[1]].arguments
+ dst_args = dst_functions[nd[1]].arguments
+ for ado in self._diff_arguments(schema, nd[1], src_args, dst_args):
+ if fdo:
+ yield fdo
+ fdo = None
+ yield ado
else:
yield fdo