Example #1
0
def _get_indexes_diffs_to_change(diffs):
    # raw diffs come in as a list of (action, index)
    index_diffs = _filter_diffs(diffs, DiffTypes.INDEX_TYPES)
    index_diffs_by_table_and_col = defaultdict(list)

    for index_diff in index_diffs:
        index = index_diff.index

        column_names = tuple(index.columns.keys())
        index_diffs_by_table_and_col[(index.table.name,
                                      column_names)].append(index_diff)

    indexes_to_change = []

    for index_diffs in index_diffs_by_table_and_col.values():
        if len(index_diffs) == 1:
            indexes_to_change.append(index_diffs[0])
        else:
            # do nothing if alembic attempts to remove and add an index on the same column
            actions = [diff.type for diff in index_diffs]
            if (len(actions) != 2 or DiffTypes.ADD_INDEX not in actions
                    or DiffTypes.REMOVE_INDEX not in actions):
                raise TableRebuildError("Unexpected diffs")

    return indexes_to_change
Example #2
0
 def rebuild_table(self):
     self.session_helper.Session.remove()
     try:
         rebuild_table(self.engine, self.get_table())
     except ProgrammingError, e:
         raise TableRebuildError(
             'problem rebuilding UCR table {}: {}'.format(self.config, e))
Example #3
0
 def build_table(self):
     self.session_helper.Session.remove()
     try:
         build_table(self.engine, self.get_table())
         self._install_partition()
     except ProgrammingError as e:
         raise TableRebuildError('problem building UCR table {}: {}'.format(self.config, e))
     finally:
         self.session_helper.Session.commit()
Example #4
0
 def rebuild_table(self, initiated_by=None, source=None, skip_log=False):
     self.log_table_rebuild(initiated_by, source, skip=skip_log)
     self.session_helper.Session.remove()
     try:
         rebuild_table(self.engine, self.get_table())
         self._apply_sql_addons()
     except (ProgrammingError, OperationalError) as e:
         raise TableRebuildError('problem rebuilding UCR table {}: {}'.format(self.config, e))
     finally:
         self.session_helper.Session.commit()
Example #5
0
 def build_table(self):
     self.session_helper.Session.remove()
     try:
         self._drop_legacy_table_and_view()
         build_table(self.engine, self.get_table())
         self._apply_sql_addons()
     except ProgrammingError as e:
         raise TableRebuildError('problem building UCR table {}: {}'.format(self.config, e))
     finally:
         self.session_helper.Session.commit()
Example #6
0
 def build_table(self, initiated_by=None, source=None):
     self.log_table_build(initiated_by, source)
     self.session_helper.Session.remove()
     try:
         build_table(self.engine, self.get_table())
         self._apply_sql_addons()
     except ProgrammingError as e:
         raise TableRebuildError('problem building UCR table {}: {}'.format(
             self.config, e))
     finally:
         self.session_helper.Session.commit()