pgtoolkit/pgdiff.py
changeset 85 11a282e23e0d
parent 83 515fadd3d286
child 87 3ef717ee9253
--- a/pgtoolkit/pgdiff.py	Wed Jul 24 13:11:37 2013 +0200
+++ b/pgtoolkit/pgdiff.py	Thu Aug 08 15:26:24 2013 +0200
@@ -252,6 +252,16 @@
         return out
 
 
+class DiffType(DiffBase):
+    def __init__(self, change, schema, name):
+        DiffBase.__init__(self)
+        self.level = 1
+        self.type = 'type'
+        self.change = change
+        self.schema = schema
+        self.name = name
+
+
 class PgDiff:
     def __init__(self, srcbrowser=None, dstbrowser=None):
         self.allowcolor = False
@@ -331,6 +341,14 @@
             diff.append(('default', a.default, b.default))
         return diff
 
+    def _compare_types(self, a, b):
+        diff = []
+        if a.type != b.type:
+            diff.append(('type', a.type, b.type))
+        if a.elements != b.elements:
+            diff.append(('elements', repr(a.elements), repr(b.elements)))
+        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:
@@ -430,6 +448,18 @@
             else:
                 yield fdo
 
+    def _diff_types(self, schema, src_types, dst_types):
+        for nd in self._diff_names(src_types, dst_types):
+            tdo = DiffType(change=nd[0], schema=schema, name=nd[1])
+            if nd[0] == '*':
+                a = src_types[nd[1]]
+                b = dst_types[nd[1]]
+                tdo.changes = self._compare_types(a, b)
+                if tdo.changes:
+                    yield tdo
+            else:
+                yield tdo
+
     def iter_diff(self):
         '''Return diff between src and dst database schema.
 
@@ -461,6 +491,14 @@
                         yield sdo
                         sdo = None
                     yield fdo
+                # types
+                src_types = src_schemas[nd[1]].types
+                dst_types = dst_schemas[nd[1]].types
+                for tdo in self._diff_types(nd[1], src_types, dst_types):
+                    if sdo:
+                        yield sdo
+                        sdo = None
+                    yield tdo
             else:
                 yield sdo