9 from pgtoolkit import pgmanager, pgbrowser, pgdiff, toolbase |
9 from pgtoolkit import pgmanager, pgbrowser, pgdiff, toolbase |
10 |
10 |
11 |
11 |
12 class SchemaDiffTool(toolbase.SrcDstTool): |
12 class SchemaDiffTool(toolbase.SrcDstTool): |
13 def __init__(self): |
13 def __init__(self): |
14 toolbase.SrcDstTool.__init__(self, name='schemadiff', desc='Database schema diff.') |
14 toolbase.SrcDstTool.__init__(self, name='schemadiff', desc='Database schema diff.', allow_reverse = True) |
15 |
15 |
16 self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter') |
16 self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter') |
17 self.parser.add_argument('-t', dest='table', nargs='*', help='Table filter') |
17 self.parser.add_argument('-t', dest='table', nargs='*', help='Table filter') |
18 self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.') |
18 self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.') |
19 |
19 |
20 self.init() |
20 self.init() |
21 |
21 |
22 def main(self): |
22 def main(self): |
23 srcbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('src')) |
23 srcbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('src')) |
24 dstbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('dst')) |
24 dstbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('dst')) |
25 |
25 |
26 pgd = pgdiff.PgDiff(srcbrowser, dstbrowser) |
26 pgd = pgdiff.PgDiff(srcbrowser, dstbrowser) |
27 |
27 |
28 if self.args.schema: |
28 if self.args.schema: |
29 pgd.filter_schemas(include=self.args.schema) |
29 pgd.filter_schemas(include=self.args.schema) |
30 |
30 |
31 if self.args.table: |
31 if self.args.table: |
32 pgd.filter_tables(include=self.args.table) |
32 pgd.filter_tables(include=self.args.table) |
33 |
33 |
34 if self.args.sql: |
34 if self.args.sql: |
35 pgd.print_patch() |
35 pgd.print_patch() |