114 self.type = 'table' |
114 self.type = 'table' |
115 self.change = change |
115 self.change = change |
116 self.schema = schema |
116 self.schema = schema |
117 self.table = table |
117 self.table = table |
118 self.name = table |
118 self.name = table |
|
119 |
|
120 |
|
121 class DiffArgument(DiffBase): |
|
122 def __init__(self, change, schema, function, argument): |
|
123 DiffBase.__init__(self) |
|
124 self.level = 2 |
|
125 self.type = 'argument' |
|
126 self.change = change |
|
127 self.schema = schema |
|
128 self.function = function |
|
129 self.argument = argument |
|
130 self.name = argument |
119 |
131 |
120 |
132 |
121 class DiffFunction(DiffBase): |
133 class DiffFunction(DiffBase): |
122 def __init__(self, change, schema, function): |
134 def __init__(self, change, schema, function): |
123 DiffBase.__init__(self) |
135 DiffBase.__init__(self) |
245 yield ('-', x) |
257 yield ('-', x) |
246 for x in dst: |
258 for x in dst: |
247 if x not in src: |
259 if x not in src: |
248 yield ('+', x) |
260 yield ('+', x) |
249 |
261 |
250 def _compare_functions(self, a, b): |
|
251 diff = [] |
|
252 if a.arguments != b.arguments: |
|
253 diff.append(('args', a.arguments, b.arguments)) |
|
254 if a.result != b.result: |
|
255 diff.append(('result', a.result, b.result)) |
|
256 if a.source != b.source: |
|
257 diff.append(('source', a.source, b.source)) |
|
258 return diff |
|
259 |
|
260 def _compare_columns(self, a, b): |
262 def _compare_columns(self, a, b): |
261 diff = [] |
263 diff = [] |
262 if a.type != b.type: |
264 if a.type != b.type: |
263 diff.append(('type', a.type, b.type)) |
265 diff.append(('type', a.type, b.type)) |
264 if a.notnull != b.notnull: |
266 if a.notnull != b.notnull: |
271 diff = [] |
273 diff = [] |
272 if a.type != b.type: |
274 if a.type != b.type: |
273 diff.append(('type', a.type, b.type)) |
275 diff.append(('type', a.type, b.type)) |
274 if a.definition != b.definition: |
276 if a.definition != b.definition: |
275 diff.append(('definition', a.definition, b.definition)) |
277 diff.append(('definition', a.definition, b.definition)) |
|
278 return diff |
|
279 |
|
280 def _compare_functions(self, a, b): |
|
281 diff = [] |
|
282 if a.result != b.result: |
|
283 diff.append(('result', a.result, b.result)) |
|
284 if a.source != b.source: |
|
285 diff.append(('source', a.source, b.source)) |
|
286 return diff |
|
287 |
|
288 def _compare_arguments(self, a, b): |
|
289 diff = [] |
|
290 if a.type != b.type: |
|
291 diff.append(('type', a.type, b.type)) |
|
292 if a.mode != b.mode: |
|
293 diff.append(('mode', a.mode, b.mode)) |
|
294 if a.default != b.default: |
|
295 diff.append(('default', a.default, b.default)) |
276 return diff |
296 return diff |
277 |
297 |
278 def _diff_columns(self, schema, table, src_columns, dst_columns): |
298 def _diff_columns(self, schema, table, src_columns, dst_columns): |
279 for nd in self._diff_names(src_columns, dst_columns): |
299 for nd in self._diff_names(src_columns, dst_columns): |
280 if nd[1] in dst_columns: |
300 if nd[1] in dst_columns: |
334 tdo = None |
354 tdo = None |
335 yield cdo |
355 yield cdo |
336 else: |
356 else: |
337 yield tdo |
357 yield tdo |
338 |
358 |
|
359 def _diff_arguments(self, schema, function, src_args, dst_args): |
|
360 for nd in self._diff_names(src_args, dst_args): |
|
361 ado = DiffArgument(change=nd[0], schema=schema, function=function, argument=nd[1]) |
|
362 if nd[0] == '*': |
|
363 a = src_args[nd[1]] |
|
364 b = dst_args[nd[1]] |
|
365 ado.changes = self._compare_arguments(a, b) |
|
366 if ado.changes: |
|
367 yield ado |
|
368 else: |
|
369 yield ado |
|
370 |
339 def _diff_functions(self, schema, src_functions, dst_functions): |
371 def _diff_functions(self, schema, src_functions, dst_functions): |
340 for nd in self._diff_names(src_functions, dst_functions): |
372 for nd in self._diff_names(src_functions, dst_functions): |
341 fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1]) |
373 fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1]) |
342 if nd[0] == '*': |
374 if nd[0] == '*': |
343 # compare function body and arguments |
375 # compare function body and result |
344 a = src_functions[nd[1]] |
376 a = src_functions[nd[1]] |
345 b = dst_functions[nd[1]] |
377 b = dst_functions[nd[1]] |
346 fdo.changes = self._compare_functions(a, b) |
378 fdo.changes = self._compare_functions(a, b) |
347 if fdo.changes: |
379 if fdo.changes: |
348 yield fdo |
380 yield fdo |
|
381 fdo = None |
|
382 # arguments |
|
383 src_args = src_functions[nd[1]].arguments |
|
384 dst_args = dst_functions[nd[1]].arguments |
|
385 for ado in self._diff_arguments(schema, nd[1], src_args, dst_args): |
|
386 if fdo: |
|
387 yield fdo |
|
388 fdo = None |
|
389 yield ado |
349 else: |
390 else: |
350 yield fdo |
391 yield fdo |
351 |
392 |
352 def iter_diff(self): |
393 def iter_diff(self): |
353 '''Return diff between src and dst database schema. |
394 '''Return diff between src and dst database schema. |