schemadiff.py
author Radek Brich <radek.brich@devl.cz>
Wed, 10 Aug 2011 18:34:54 +0200
changeset 6 4ab077c93b2d
parent 5 57cf8fdff5ed
child 7 685b20d2d3ab
permissions -rwxr-xr-x
Add table diff tool.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3.2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from pgtools import pgmanager, pgbrowser, pgdiff
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
     4
from toolbase import SrcDstTool
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
     7
class SchemaDiffTool(SrcDstTool):
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
     8
    def __init__(self):
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
     9
        SrcDstTool.__init__(self, name='schemadiff', desc='Database schema diff.')
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    10
        
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    11
        self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter')
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    12
        self.parser.add_argument('-t', dest='table', nargs='*', help='Table filter')
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    13
        
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    14
        self.init()
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    16
    def main(self):
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    17
        srcbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('src'))
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    18
        dstbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('dst'))
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    20
        pgd = pgdiff.PgDiff(srcbrowser, dstbrowser)
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    22
        if self.args.schema:
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    23
            pgd.filter_schemas(include=self.args.schema)
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    24
        
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    25
        if self.args.table:
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    26
            pgd.filter_tables(include=self.args.table)
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    28
        pgd.print_diff()
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    29
2
efee419b7a2d Fix pgmanager exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
5
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    31
tool = SchemaDiffTool()
57cf8fdff5ed Clean up tools.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
    32
tool.main()