| author | Radek Brich <radek.brich@devl.cz> | 
| Sat, 29 Sep 2012 13:53:54 +0200 | |
| changeset 49 | 08e4dfe1b0cb | 
| parent 47 | bb8c729ae6ce | 
| child 53 | 4a049a5af657 | 
| permissions | -rw-r--r-- | 
| 0 | 1 | # -*- coding: utf-8 -*- | 
| 2 | # | |
| 3 | # PgDiff - capture differences of database metadata | |
| 4 | # | |
| 5 | # Depends on PgBrowser | |
| 6 | # | |
| 7 | # Copyright (c) 2011 Radek Brich <radek.brich@devl.cz> | |
| 8 | # | |
| 9 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 10 | # of this software and associated documentation files (the "Software"), to deal | |
| 11 | # in the Software without restriction, including without limitation the rights | |
| 12 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 13 | # copies of the Software, and to permit persons to whom the Software is | |
| 14 | # furnished to do so, subject to the following conditions: | |
| 15 | # | |
| 16 | # The above copyright notice and this permission notice shall be included in | |
| 17 | # all copies or substantial portions of the Software. | |
| 18 | # | |
| 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 20 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 21 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 22 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 23 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| 25 | # THE SOFTWARE. | |
| 26 | ||
| 27 | ||
| 9 
2fcc8ef0b97d
Reorganize again :-) Add setup.py.
 Radek Brich <radek.brich@devl.cz> parents: 
7diff
changeset | 28 | from pgtoolkit.highlight import * | 
| 0 | 29 | |
| 30 | ||
| 31 | class DiffBase: | |
| 6 | 32 |     COLORS = {
 | 
| 33 | '+' : BOLD | GREEN, | |
| 34 | '-' : BOLD | RED, | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 35 | '*' : BOLD | YELLOW, | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 36 | } | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 37 | |
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 38 |     COMMANDS = {
 | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 39 | '+' : 'CREATE', | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 40 | '-' : 'DROP', | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 41 | '*' : 'ALTER', | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 42 | } | 
| 6 | 43 | |
| 0 | 44 | def __init__(self): | 
| 45 | self.changes = None | |
| 46 | ||
| 47 | def format(self): | |
| 48 | out = [' ' * self.level] | |
| 49 | ||
| 6 | 50 | out.append(highlight(1, self.COLORS[self.change])) | 
| 0 | 51 | out.append(self.change) | 
| 52 | ||
| 53 | out += [' ', self.type, ' ', self.name, highlight(0)] | |
| 54 | ||
| 55 | if self.changes: | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 56 |             out += [highlight(1, WHITE), ' (', self._formatchanges(), ')', highlight(0)]
 | 
| 0 | 57 | |
| 58 | return ''.join(out) | |
| 59 | ||
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 60 | def _formatnotnull(self, notnull): | 
| 0 | 61 | if notnull: | 
| 62 | return 'NOT NULL' | |
| 63 | else: | |
| 64 | return None | |
| 65 | ||
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 66 | def _formatchanges(self): | 
| 0 | 67 | res = [] | 
| 68 | for x in self.changes: | |
| 69 | type, a, b = x | |
| 70 | if type == 'notnull': | |
| 71 | type = '' | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 72 | a = self._formatnotnull(a) | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 73 | b = self._formatnotnull(b) | 
| 0 | 74 | |
| 75 | if a and b: | |
| 76 | s = ''.join(['Changed ', type, ' from ', | |
| 77 | highlight(1,15), a, highlight(0), ' to ', | |
| 78 | highlight(1,15), b, highlight(0), '.']) | |
| 79 | elif a and not b: | |
| 80 | l = ['Removed '] | |
| 81 | if type: | |
| 82 | l += [type, ' '] | |
| 83 | l += [highlight(1,15), a, highlight(0), '.'] | |
| 84 | s = ''.join(l) | |
| 85 | elif b and not a: | |
| 86 | l = ['Added '] | |
| 87 | if type: | |
| 88 | l += [type, ' '] | |
| 89 | l += [highlight(1,15), b, highlight(0), '.'] | |
| 90 | s = ''.join(l) | |
| 91 | res.append(s) | |
| 92 | return ' '.join(res) | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 93 | |
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 94 | def format_patch(self): | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 95 |         if self.change == '*' and self.type in ('schema', 'table'):
 | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 96 | return None | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 97 | return '%s %s %s;' % (self.COMMANDS[self.change], self.type.upper(), self.name) | 
| 0 | 98 | |
| 99 | ||
| 100 | class DiffSchema(DiffBase): | |
| 101 | def __init__(self, change, schema): | |
| 102 | DiffBase.__init__(self) | |
| 103 | self.level = 0 | |
| 104 | self.type = 'schema' | |
| 105 | self.change = change | |
| 106 | self.schema = schema | |
| 107 | self.name = schema | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 108 | |
| 0 | 109 | |
| 110 | class DiffTable(DiffBase): | |
| 111 | def __init__(self, change, schema, table): | |
| 112 | DiffBase.__init__(self) | |
| 113 | self.level = 1 | |
| 114 | self.type = 'table' | |
| 115 | self.change = change | |
| 116 | self.schema = schema | |
| 117 | self.table = table | |
| 118 | self.name = table | |
| 119 | ||
| 120 | ||
| 121 | class DiffColumn(DiffBase): | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 122 |     ALTER_COMMANDS = {
 | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 123 | '+' : 'ADD', | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 124 | '-' : 'DROP', | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 125 | '*' : 'ALTER', | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 126 | } | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 127 | |
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 128 | def __init__(self, change, schema, table, column, columntype, columndefault, changes=None): | 
| 0 | 129 | DiffBase.__init__(self) | 
| 130 | self.level = 2 | |
| 131 | self.type = 'column' | |
| 132 | self.change = change | |
| 133 | self.schema = schema | |
| 134 | self.table = table | |
| 135 | self.column = column | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 136 | self.columntype = columntype | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 137 | self.columndefault = columndefault | 
| 0 | 138 | self.name = column | 
| 139 | self.changes = changes | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 140 | |
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 141 | def format_patch(self): | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 142 | out = 'ALTER TABLE %s.%s %s COLUMN %s %s' % ( | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 143 | self.schema, | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 144 | self.table, | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 145 | self.ALTER_COMMANDS[self.change], | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 146 | self.name, | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 147 | self.columntype | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 148 | ) | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 149 | if self.columndefault: | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 150 | out += ' DEFAULT ' + self.columndefault | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 151 | out += ';' | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 152 | return out | 
| 0 | 153 | |
| 154 | ||
| 155 | class DiffConstraint(DiffBase): | |
| 156 | def __init__(self, change, schema, table, constraint, changes=None): | |
| 157 | DiffBase.__init__(self) | |
| 158 | self.level = 2 | |
| 159 | self.type = 'constraint' | |
| 160 | self.change = change | |
| 161 | self.schema = schema | |
| 162 | self.table = table | |
| 163 | self.constraint = constraint | |
| 164 | self.name = constraint | |
| 165 | self.changes = changes | |
| 166 | ||
| 167 | ||
| 168 | class PgDiff: | |
| 169 | def __init__(self, srcbrowser=None, dstbrowser=None): | |
| 170 | self.allowcolor = False | |
| 171 | self.src = srcbrowser | |
| 172 | self.dst = dstbrowser | |
| 173 | self.include_schemas = set() # if not empty, consider only these schemas for diff | |
| 174 | self.exclude_schemas = set() # exclude these schemas from diff | |
| 175 | self.include_tables = set() | |
| 176 | self.exclude_tables = set() | |
| 177 | ||
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 178 | def _test_schema(self, schema): | 
| 0 | 179 | if self.include_schemas and schema not in self.include_schemas: | 
| 180 | return False | |
| 181 | if schema in self.exclude_schemas: | |
| 182 | return False | |
| 183 | return True | |
| 184 | ||
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 185 | def _test_table(self, table): | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 186 | if self.include_tables and table not in self.include_tables: | 
| 0 | 187 | return False | 
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 188 | if table in self.exclude_tables: | 
| 0 | 189 | return False | 
| 190 | return True | |
| 191 | ||
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 192 | def _diff_names(self, src, dst): | 
| 0 | 193 | for x in src: | 
| 194 | if x in dst: | |
| 195 |                 yield ('*', x)
 | |
| 196 | else: | |
| 197 |                 yield ('-', x)
 | |
| 198 | for x in dst: | |
| 199 | if x not in src: | |
| 200 |                 yield ('+', x)
 | |
| 201 | ||
| 202 | def _compare_columns(self, a, b): | |
| 203 | diff = [] | |
| 204 | if a.type != b.type: | |
| 205 |             diff.append(('type', a.type, b.type))
 | |
| 206 | if a.notnull != b.notnull: | |
| 207 |             diff.append(('notnull', a.notnull, b.notnull))
 | |
| 208 | if a.default != b.default: | |
| 209 |             diff.append(('default', a.default, b.default))
 | |
| 210 | return diff | |
| 211 | ||
| 212 | def _compare_constraints(self, a, b): | |
| 213 | diff = [] | |
| 214 | if a.type != b.type: | |
| 215 |             diff.append(('type', a.type, b.type))
 | |
| 216 | if a.definition != b.definition: | |
| 217 |             diff.append(('definition', a.definition, b.definition))
 | |
| 218 | return diff | |
| 219 | ||
| 220 | def _diff_columns(self, schema, table, src_columns, dst_columns): | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 221 | for nd in self._diff_names(src_columns, dst_columns): | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 222 | cdo = DiffColumn(change=nd[0], schema=schema, table=table, column=nd[1], | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 223 | columntype=dst_columns[nd[1]].type, columndefault=dst_columns[nd[1]].default) | 
| 0 | 224 | if nd[0] == '*': | 
| 225 | a = src_columns[nd[1]] | |
| 226 | b = dst_columns[nd[1]] | |
| 227 | cdo.changes = self._compare_columns(a, b) | |
| 228 | if cdo.changes: | |
| 229 | yield cdo | |
| 230 | else: | |
| 231 | yield cdo | |
| 232 | ||
| 233 | def _diff_constraints(self, schema, table, src_constraints, dst_constraints): | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 234 | for nd in self._diff_names(src_constraints, dst_constraints): | 
| 0 | 235 | cdo = DiffConstraint(change=nd[0], schema=schema, table=table, constraint=nd[1]) | 
| 236 | if nd[0] == '*': | |
| 237 | a = src_constraints[nd[1]] | |
| 238 | b = dst_constraints[nd[1]] | |
| 239 | cdo.changes = self._compare_constraints(a, b) | |
| 240 | if cdo.changes: | |
| 241 | yield cdo | |
| 242 | else: | |
| 243 | yield cdo | |
| 244 | ||
| 245 | def _difftables(self, schema, src_tables, dst_tables): | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 246 | for nd in self._diff_names(src_tables, dst_tables): | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 247 | if not self._test_table(nd[1]): | 
| 0 | 248 | continue | 
| 249 | tdo = DiffTable(change=nd[0], schema=schema, table=nd[1]) | |
| 250 | if nd[0] == '*': | |
| 251 | # columns | |
| 252 | src_columns = src_tables[nd[1]].columns | |
| 253 | dst_columns = dst_tables[nd[1]].columns | |
| 254 | for cdo in self._diff_columns(schema, nd[1], src_columns, dst_columns): | |
| 255 | if tdo: | |
| 256 | yield tdo | |
| 257 | tdo = None | |
| 258 | yield cdo | |
| 259 | # constraints | |
| 260 | src_constraints = src_tables[nd[1]].constraints | |
| 261 | dst_constraints = dst_tables[nd[1]].constraints | |
| 262 | for cdo in self._diff_constraints(schema, nd[1], src_constraints, dst_constraints): | |
| 263 | if tdo: | |
| 264 | yield tdo | |
| 265 | tdo = None | |
| 266 | yield cdo | |
| 267 | else: | |
| 268 | yield tdo | |
| 269 | ||
| 270 | def iter_diff(self): | |
| 271 | '''Return diff between src and dst database schema. | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 272 | |
| 0 | 273 | Yields one line at the time. Each line is in form of object | 
| 274 | iherited from DiffBase. This object contains all information | |
| 275 | about changes. See format() method. | |
| 276 | ||
| 277 | ''' | |
| 278 | src_schemas = self.src.schemas | |
| 279 | dst_schemas = self.dst.schemas | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 280 | src = [x.name for x in src_schemas.values() if not x.system and self._test_schema(x.name)] | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 281 | dst = [x.name for x in dst_schemas.values() if not x.system and self._test_schema(x.name)] | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 282 | for nd in self._diff_names(src, dst): | 
| 0 | 283 | sdo = DiffSchema(change=nd[0], schema=nd[1]) | 
| 284 | if nd[0] == '*': | |
| 285 | src_tables = src_schemas[nd[1]].tables | |
| 286 | dst_tables = dst_schemas[nd[1]].tables | |
| 287 | for tdo in self._difftables(nd[1], src_tables, dst_tables): | |
| 288 | if sdo: | |
| 289 | yield sdo | |
| 290 | sdo = None | |
| 291 | yield tdo | |
| 292 | else: | |
| 293 | yield sdo | |
| 294 | ||
| 295 | def print_diff(self): | |
| 296 | '''Print diff between src and dst database schema. | |
| 297 | ||
| 298 | The output is in human readable form. | |
| 299 | ||
| 300 | Set allowcolor=True of PgDiff instance to get colored output. | |
| 301 | ||
| 302 | ''' | |
| 303 | for ln in self.iter_diff(): | |
| 304 | print(ln.format()) | |
| 305 | ||
| 306 | def print_patch(self): | |
| 307 | '''Print patch for updating from src schema to dst schema. | |
| 308 | ||
| 309 | Supports table drop, add, column drop, add and following | |
| 310 | changes of columns: | |
| 311 | - type | |
| 312 | - set/remove not null | |
| 313 | - default value | |
| 314 | ||
| 315 | This is experimental, not tested very much. | |
| 316 | Do not use without checking the commands. | |
| 317 | Even if it works as intended, it can cause table lock ups | |
| 318 | and/or loss of data. You have been warned. | |
| 319 | ||
| 320 | ''' | |
| 321 | for ln in self.iter_diff(): | |
| 47 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 322 | patch = ln.format_patch() | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 323 | if patch: | 
| 
bb8c729ae6ce
PgDiff: add partial support for SQL patch.
 Radek Brich <radek.brich@devl.cz> parents: 
9diff
changeset | 324 | print(patch) | 
| 0 | 325 | |
| 326 | def filter_schemas(self, include=[], exclude=[]): | |
| 327 | '''Modify list of schemas which are used for computing diff. | |
| 328 | ||
| 329 | include (list) -- if not empty, consider only these schemas for diff | |
| 330 | exclude (list) -- exclude these schemas from diff | |
| 331 | ||
| 332 | Order: include, exclude | |
| 333 | include=[] means include everything | |
| 334 | ''' | |
| 335 | self.include_schemas.clear() | |
| 336 | self.include_schemas.update(include) | |
| 337 | self.exclude_schemas.clear() | |
| 338 | self.exclude_schemas.update(exclude) | |
| 339 | ||
| 340 | ||
| 341 | def filter_tables(self, include=[], exclude=[]): | |
| 342 | self.include_tables.clear() | |
| 343 | self.include_tables.update(include) | |
| 344 | self.exclude_tables.clear() | |
| 345 | self.exclude_tables.update(exclude) | |
| 346 |