250 if self.change == '-': |
250 if self.change == '-': |
251 out = [q_drop] |
251 out = [q_drop] |
252 return out |
252 return out |
253 |
253 |
254 |
254 |
|
255 class DiffType(DiffBase): |
|
256 def __init__(self, change, schema, name): |
|
257 DiffBase.__init__(self) |
|
258 self.level = 1 |
|
259 self.type = 'type' |
|
260 self.change = change |
|
261 self.schema = schema |
|
262 self.name = name |
|
263 |
|
264 |
255 class PgDiff: |
265 class PgDiff: |
256 def __init__(self, srcbrowser=None, dstbrowser=None): |
266 def __init__(self, srcbrowser=None, dstbrowser=None): |
257 self.allowcolor = False |
267 self.allowcolor = False |
258 self.src = srcbrowser |
268 self.src = srcbrowser |
259 self.dst = dstbrowser |
269 self.dst = dstbrowser |
327 diff.append(('type', a.type, b.type)) |
337 diff.append(('type', a.type, b.type)) |
328 if a.mode != b.mode: |
338 if a.mode != b.mode: |
329 diff.append(('mode', a.mode, b.mode)) |
339 diff.append(('mode', a.mode, b.mode)) |
330 if a.default != b.default: |
340 if a.default != b.default: |
331 diff.append(('default', a.default, b.default)) |
341 diff.append(('default', a.default, b.default)) |
|
342 return diff |
|
343 |
|
344 def _compare_types(self, a, b): |
|
345 diff = [] |
|
346 if a.type != b.type: |
|
347 diff.append(('type', a.type, b.type)) |
|
348 if a.elements != b.elements: |
|
349 diff.append(('elements', repr(a.elements), repr(b.elements))) |
332 return diff |
350 return diff |
333 |
351 |
334 def _diff_columns(self, schema, table, src_columns, dst_columns): |
352 def _diff_columns(self, schema, table, src_columns, dst_columns): |
335 for nd in self._diff_names(src_columns, dst_columns): |
353 for nd in self._diff_names(src_columns, dst_columns): |
336 if nd[1] in dst_columns: |
354 if nd[1] in dst_columns: |
428 fdo = None |
446 fdo = None |
429 yield ado |
447 yield ado |
430 else: |
448 else: |
431 yield fdo |
449 yield fdo |
432 |
450 |
|
451 def _diff_types(self, schema, src_types, dst_types): |
|
452 for nd in self._diff_names(src_types, dst_types): |
|
453 tdo = DiffType(change=nd[0], schema=schema, name=nd[1]) |
|
454 if nd[0] == '*': |
|
455 a = src_types[nd[1]] |
|
456 b = dst_types[nd[1]] |
|
457 tdo.changes = self._compare_types(a, b) |
|
458 if tdo.changes: |
|
459 yield tdo |
|
460 else: |
|
461 yield tdo |
|
462 |
433 def iter_diff(self): |
463 def iter_diff(self): |
434 '''Return diff between src and dst database schema. |
464 '''Return diff between src and dst database schema. |
435 |
465 |
436 Yields one line at the time. Each line is in form of object |
466 Yields one line at the time. Each line is in form of object |
437 iherited from DiffBase. This object contains all information |
467 iherited from DiffBase. This object contains all information |
459 for fdo in self._diff_functions(nd[1], src_functions, dst_functions): |
489 for fdo in self._diff_functions(nd[1], src_functions, dst_functions): |
460 if sdo: |
490 if sdo: |
461 yield sdo |
491 yield sdo |
462 sdo = None |
492 sdo = None |
463 yield fdo |
493 yield fdo |
|
494 # types |
|
495 src_types = src_schemas[nd[1]].types |
|
496 dst_types = dst_schemas[nd[1]].types |
|
497 for tdo in self._diff_types(nd[1], src_types, dst_types): |
|
498 if sdo: |
|
499 yield sdo |
|
500 sdo = None |
|
501 yield tdo |
464 else: |
502 else: |
465 yield sdo |
503 yield sdo |
466 |
504 |
467 def print_diff(self): |
505 def print_diff(self): |
468 '''Print diff between src and dst database schema. |
506 '''Print diff between src and dst database schema. |