pgtoolkit/pgdiff.py
changeset 94 a10f553e6f6a
parent 87 3ef717ee9253
equal deleted inserted replaced
93:b72591087495 94:a10f553e6f6a
   135         self.argument = argument
   135         self.argument = argument
   136         self.name = argument
   136         self.name = argument
   137 
   137 
   138 
   138 
   139 class DiffFunction(DiffBase):
   139 class DiffFunction(DiffBase):
   140     def __init__(self, change, schema, function, show_body_diff=False):
   140     def __init__(self, change, schema, function, definition, show_body_diff=False):
   141         DiffBase.__init__(self)
   141         DiffBase.__init__(self)
   142         self.level = 1
   142         self.level = 1
   143         self.type = 'function'
   143         self.type = 'function'
   144         self.change = change
   144         self.change = change
   145         self.schema = schema
   145         self.schema = schema
   146         self.function = function
   146         self.function = function
       
   147         #: New function definition
       
   148         self.definition = definition
   147         self.name = function
   149         self.name = function
   148         self.show_body_diff = show_body_diff
   150         self.show_body_diff = show_body_diff
   149 
   151 
   150     def _formatchanges(self):
   152     def _formatchanges(self):
   151         res = []
   153         res = []
   165             else:
   167             else:
   166                 res.append(''.join(['Changed ', type, ' from ',
   168                 res.append(''.join(['Changed ', type, ' from ',
   167                     highlight(1,15), a, highlight(0), ' to ',
   169                     highlight(1,15), a, highlight(0), ' to ',
   168                     highlight(1,15), b, highlight(0), '.']))
   170                     highlight(1,15), b, highlight(0), '.']))
   169         return ' '.join(res)
   171         return ' '.join(res)
       
   172 
       
   173     def format_patch(self):
       
   174         return [self.definition]
   170 
   175 
   171 
   176 
   172 class DiffColumn(DiffBase):
   177 class DiffColumn(DiffBase):
   173     ALTER_COMMANDS = {
   178     ALTER_COMMANDS = {
   174         '+' : 'ADD',
   179         '+' : 'ADD',
   482 
   487 
   483     def _diff_functions(self, schema, src_functions, dst_functions):
   488     def _diff_functions(self, schema, src_functions, dst_functions):
   484         for nd in self._diff_names(src_functions, dst_functions):
   489         for nd in self._diff_names(src_functions, dst_functions):
   485             if not self._test_function(nd[1]):
   490             if not self._test_function(nd[1]):
   486                 continue
   491                 continue
   487             fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1], show_body_diff=self.function_body_diff)
   492             if nd[1] in dst_functions:
       
   493                 dst_definition = dst_functions[nd[1]].definition
       
   494             else:
       
   495                 dst_definition = None
       
   496             fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1],
       
   497                                definition=dst_definition,
       
   498                                show_body_diff=self.function_body_diff)
   488             if nd[0] == '*':
   499             if nd[0] == '*':
   489                 # compare function body and result
   500                 # compare function body and result
   490                 a = src_functions[nd[1]]
   501                 a = src_functions[nd[1]]
   491                 b = dst_functions[nd[1]]
   502                 b = dst_functions[nd[1]]
   492                 fdo.changes = self._compare_functions(a, b)
   503                 fdo.changes = self._compare_functions(a, b)