author | Radek Brich <radek.brich@devl.cz> |
Thu, 31 Jan 2013 13:24:57 +0100 | |
changeset 63 | 8c7f0a51ba50 |
parent 61 | 703bba757605 |
child 93 | b72591087495 |
permissions | -rwxr-xr-x |
2 | 1 |
#!/usr/bin/env python3.2 |
44
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
2 |
# |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
3 |
# Print differences in database schema. |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
4 |
# |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
5 |
# Prints changes from source to destination. |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
6 |
# SQL patch updates source database schema to destination schema. |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
7 |
# |
2 | 8 |
|
9
2fcc8ef0b97d
Reorganize again :-) Add setup.py.
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
9 |
from pgtoolkit import pgmanager, pgbrowser, pgdiff, toolbase |
2 | 10 |
|
11 |
||
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
12 |
class SchemaDiffTool(toolbase.SrcDstTool): |
5 | 13 |
def __init__(self): |
56
94e091c23ebb
Add reverse parameter for diff tools.
Radek Brich <radek.brich@devl.cz>
parents:
44
diff
changeset
|
14 |
toolbase.SrcDstTool.__init__(self, name='schemadiff', desc='Database schema diff.', allow_reverse = True) |
94e091c23ebb
Add reverse parameter for diff tools.
Radek Brich <radek.brich@devl.cz>
parents:
44
diff
changeset
|
15 |
|
5 | 16 |
self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter') |
17 |
self.parser.add_argument('-t', dest='table', nargs='*', help='Table filter') |
|
63
8c7f0a51ba50
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
18 |
self.parser.add_argument('-f', dest='function', type=str, help='Function filter (regex)') |
16
cb7e13711a99
MyManager - create_conn() - allow same parameters as for PgManager.
Radek Brich <brich.radek@ifortuna.cz>
parents:
9
diff
changeset
|
19 |
self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.') |
63
8c7f0a51ba50
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
20 |
self.parser.add_argument('--body', action='store_true', help='Output diff for function bodies.') |
56
94e091c23ebb
Add reverse parameter for diff tools.
Radek Brich <radek.brich@devl.cz>
parents:
44
diff
changeset
|
21 |
|
5 | 22 |
self.init() |
2 | 23 |
|
5 | 24 |
def main(self): |
25 |
srcbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('src')) |
|
26 |
dstbrowser = pgbrowser.PgBrowser(self.pgm.get_conn('dst')) |
|
56
94e091c23ebb
Add reverse parameter for diff tools.
Radek Brich <radek.brich@devl.cz>
parents:
44
diff
changeset
|
27 |
|
5 | 28 |
pgd = pgdiff.PgDiff(srcbrowser, dstbrowser) |
2 | 29 |
|
61
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
30 |
try: |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
31 |
if self.args.schema: |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
32 |
pgd.filter_schemas(include=self.args.schema) |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
33 |
if self.args.table: |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
34 |
pgd.filter_tables(include=self.args.table) |
63
8c7f0a51ba50
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
35 |
if self.args.function: |
8c7f0a51ba50
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
36 |
pgd.filter_functions(self.args.function) |
8c7f0a51ba50
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
37 |
if self.args.body: |
8c7f0a51ba50
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
38 |
pgd.function_body_diff = True |
56
94e091c23ebb
Add reverse parameter for diff tools.
Radek Brich <radek.brich@devl.cz>
parents:
44
diff
changeset
|
39 |
|
61
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
40 |
if self.args.sql: |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
41 |
pgd.print_patch() |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
42 |
else: |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
43 |
pgd.print_diff() |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
44 |
except pgdiff.PgDiffError as e: |
703bba757605
PgDiff: check schema existance.
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
45 |
print('PgDiff error:', str(e)) |
5 | 46 |
|
2 | 47 |
|
5 | 48 |
tool = SchemaDiffTool() |
49 |
tool.main() |