schemadiff.py
changeset 63 8c7f0a51ba50
parent 61 703bba757605
child 93 b72591087495
equal deleted inserted replaced
62:af637235ca81 63:8c7f0a51ba50
    13     def __init__(self):
    13     def __init__(self):
    14         toolbase.SrcDstTool.__init__(self, name='schemadiff', desc='Database schema diff.', allow_reverse = True)
    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('-f', dest='function', type=str, help='Function filter (regex)')
    18         self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.')
    19         self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.')
       
    20         self.parser.add_argument('--body', action='store_true', help='Output diff for function bodies.')
    19 
    21 
    20         self.init()
    22         self.init()
    21 
    23 
    22     def main(self):
    24     def main(self):
    23         srcbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('src'))
    25         srcbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('src'))
    26         pgd = pgdiff.PgDiff(srcbrowser, dstbrowser)
    28         pgd = pgdiff.PgDiff(srcbrowser, dstbrowser)
    27 
    29 
    28         try:
    30         try:
    29             if self.args.schema:
    31             if self.args.schema:
    30                 pgd.filter_schemas(include=self.args.schema)
    32                 pgd.filter_schemas(include=self.args.schema)
    31 
       
    32             if self.args.table:
    33             if self.args.table:
    33                 pgd.filter_tables(include=self.args.table)
    34                 pgd.filter_tables(include=self.args.table)
       
    35             if self.args.function:
       
    36                 pgd.filter_functions(self.args.function)
       
    37             if self.args.body:
       
    38                 pgd.function_body_diff = True
    34 
    39 
    35             if self.args.sql:
    40             if self.args.sql:
    36                 pgd.print_patch()
    41                 pgd.print_patch()
    37             else:
    42             else:
    38                 pgd.print_diff()
    43                 pgd.print_diff()