Try to find indexes that only changed their name,
        rename operations maybe cheaper than add/drop
        however ambiguities between different possibilities
        should not lead to renaming at all.

        :type table_differences: TableDiff
437663
def detect_index_renamings(self, table_differences):
        
        rename_candidates = OrderedDict()

        # Gather possible rename candidates by comparing
        # each added and removed index based on semantics.
        for added_index_name, added_index in table_differences.added_indexes.items():
            for removed_index in table_differences.removed_indexes.values():
                if not self.diff_index(added_index, removed_index):
                    if added_index.get_name() not in rename_candidates:
                        rename_candidates[added_index.get_name()] = []

                    rename_candidates[added_index.get_name()].append(
                        (removed_index, added_index, added_index_name)
                    )

        for candidate_indexes in rename_candidates.values():
            # If the current rename candidate contains exactly one semantically equal index,
            # we can safely rename it.
            # Otherwise it is unclear if a rename action is really intended,
            # therefore we let those ambiguous indexes be added/dropped.
            if len(candidate_indexes) == 1:
                removed_index, added_index, _ = candidate_indexes[0]

                removed_index_name = removed_index.get_name().lower()
                added_index_name = added_index.get_name().lower()

                if not removed_index_name in table_differences.renamed_indexes:
                    table_differences.renamed_indexes[removed_index_name] = added_index
                    del table_differences.added_indexes[added_index_name]
                    del table_differences.removed_indexes[removed_index_name]
659794
public function checkDiff($tableName, TableDiff $diff)
    {
        $this->diffs[$tableName] = $diff;

        // Adds
        $this->getAddedColumns($tableName, $diff);
        $this->getAddedIndexes($tableName, $diff);
        $this->getAddedForeignKeys($tableName, $diff);

        // Changes
        $this->getChangedColumns($tableName, $diff);
        $this->getChangedIndexes($tableName, $diff);
        $this->getChangedForeignKeys($tableName, $diff);

        // Renames
        $this->getRenamedColumns($tableName, $diff);

        // Removes
        $this->getRemovedColumns($tableName, $diff);
        $this->getRemovedIndexes($tableName, $diff);
        $this->getRemovedForeignKeys($tableName, $diff);

        if (count($diff->removedColumns) > 0) {
            $hint = sprintf(
                'The following fields in the `%s` table are not defined in your configuration. You can safely delete them manually if they are no longer needed: `%s`',
                $tableName,
                implode('`, `', array_keys($diff->removedColumns))
            );
            $this->hints[] = $hint;
        }
    }
1006339
def drop_index(index_name)
			transaction {
				ODBA.storage.drop_index(index_name)
				self.delete(self.indices[index_name]) 
			}
		end
371707
def change_column_if_table_exists(self,
                                      tablename: str,
                                      oldfieldname: str,
                                      newfieldname: str,
                                      newdef: str) -> Optional[int]:
        """"""
        if not self.table_exists(tablename):
            return None
        if not self.column_exists(tablename, oldfieldname):
            return None
        sql = "ALTER TABLE {t} CHANGE COLUMN {old} {new} {newdef}".format(
            t=tablename,
            old=oldfieldname,
            new=newfieldname,
            newdef=newdef,
        )
        log.info(sql)
        return self.db_exec_literal(sql)
222737
def _get_changed_diff(self, blueprint, schema):
        
        table = schema.list_table_details(
            self.get_table_prefix() + blueprint.get_table()
        )

        return Comparator().diff_table(
            table, self._get_table_with_column_changes(blueprint, table)
        )
1335793
def _get_column_names_in_altered_table(self, diff):
        
        columns = OrderedDict()

        for column_name, column in diff.from_table.get_columns().items():
            columns[column_name.lower()] = column.get_name()

        for column_name, column in diff.removed_columns.items():
            column_name = column_name.lower()
            if column_name in columns:
                del columns[column_name]

        for old_column_name, column in diff.renamed_columns.items():
            column_name = column.get_name()
            columns[old_column_name.lower()] = column_name
            columns[column_name.lower()] = column_name

        for old_column_name, column_diff in diff.changed_columns.items():
            column_name = column_diff.column.get_name()
            columns[old_column_name.lower()] = column_name
            columns[column_name.lower()] = column_name

        for column_name, column in diff.added_columns.items():
            columns[column_name.lower()] = column_name

        return columns
1332965
def _valid_table_name(self, table):
        
        if table is None or not len(table.strip()):
            raise ValueError("Invalid table name: %r" % table)
        return table.strip()
1294926
def rename_table(self, from_table: str, to_table: str) -> Optional[int]:
        """"""
        if not self.table_exists(from_table):
            log.info("Skipping renaming of table " + from_table +
                     " (doesn't exist)")
            return None
        if self.table_exists(to_table):
            raise RuntimeError("Can't rename table {} to {}: destination "
                               "already exists!".format(from_table, to_table))
        log.info("Renaming table {} to {}", from_table, to_table)
        sql = "RENAME TABLE {} TO {}".format(from_table, to_table)
        return self.db_exec_literal(sql)
532533
def get_columns_diff(changes):
    
    for change in changes:
        change.diff = []
        elt_changes = change.get_changes()
        if elt_changes:
            change.diff = elt_changes.columns

    return changes
1178486
def tablerename(tablename, newtablename):
    
    t = table(tablename, ack=False)
    t.rename(newtablename)
564385
public function getModifyTableDDL(TableDiff $tableDiff)
    {
        $ret = '';

        $toTable = $tableDiff->getToTable();

        // drop indices, foreign keys
        foreach ($tableDiff->getRemovedFks() as $fk) {
            $ret .= $this->getDropForeignKeyDDL($fk);
        }
        foreach ($tableDiff->getModifiedFks() as $fkModification) {
            list($fromFk) = $fkModification;
            $ret .= $this->getDropForeignKeyDDL($fromFk);
        }
        foreach ($tableDiff->getRemovedIndices() as $index) {
            $ret .= $this->getDropIndexDDL($index);
        }
        foreach ($tableDiff->getModifiedIndices() as $indexModification) {
            list($fromIndex) = $indexModification;
            $ret .= $this->getDropIndexDDL($fromIndex);
        }

        $columnChanges = '';

        // alter table structure
        if ($tableDiff->hasModifiedPk()) {
            $columnChanges .= $this->getDropPrimaryKeyDDL($tableDiff->getFromTable());
        }
        foreach ($tableDiff->getRenamedColumns() as $columnRenaming) {
            $columnChanges .= $this->getRenameColumnDDL($columnRenaming[0], $columnRenaming[1]);
        }
        if ($modifiedColumns = $tableDiff->getModifiedColumns()) {
            $columnChanges .= $this->getModifyColumnsDDL($modifiedColumns);
        }
        if ($addedColumns = $tableDiff->getAddedColumns()) {
            $columnChanges .= $this->getAddColumnsDDL($addedColumns);
        }
        foreach ($tableDiff->getRemovedColumns() as $column) {
            $columnChanges .= $this->getRemoveColumnDDL($column);
        }

        // add new indices and foreign keys
        if ($tableDiff->hasModifiedPk()) {
            $columnChanges .= $this->getAddPrimaryKeyDDL($tableDiff->getToTable());
        }

        if ($columnChanges) {
            //merge column changes into one command. This is more compatible especially with PK constraints.

            $changes = explode(';', $columnChanges);
            $columnChanges = [];

            foreach ($changes as $change) {
                if (!trim($change)) continue;
                $isCompatibleCall = preg_match(
                    sprintf('/ALTER TABLE %s (?!RENAME)/', $this->quoteIdentifier($toTable->getName())),
                    $change
                );
                if ($isCompatibleCall) {
                    $columnChanges[] = preg_replace(
                        sprintf('/ALTER TABLE %s /', $this->quoteIdentifier($toTable->getName())),
                        "\n\n  ",
                        trim($change)
                    );
                } else {
                    $ret .= $change.";\n";
                }
            }

            if (0 < count($columnChanges)) {
                $ret .= sprintf("
ALTER TABLE %s%s;
",
                    $this->quoteIdentifier($toTable->getName()), implode(',', $columnChanges));
            }
        }

        // create indices, foreign keys
        foreach ($tableDiff->getModifiedIndices() as $indexModification) {
            list($oldIndex, $toIndex) = $indexModification;
            $ret .= $this->getAddIndexDDL($toIndex);
        }
        foreach ($tableDiff->getAddedIndices() as $index) {
            $ret .= $this->getAddIndexDDL($index);
        }
        foreach ($tableDiff->getModifiedFks() as $fkModification) {
            list(, $toFk) = $fkModification;
            $ret .= $this->getAddForeignKeyDDL($toFk);
        }
        foreach ($tableDiff->getAddedFks() as $fk) {
            $ret .= $this->getAddForeignKeyDDL($fk);
        }

        return $ret;
    }
573868
private void renameIndexTables(AccumuloTable oldTable, AccumuloTable newTable)
    {
        if (!oldTable.isIndexed()) {
            return;
        }

        if (!tableManager.exists(oldTable.getIndexTableName())) {
            throw new PrestoException(ACCUMULO_TABLE_DNE, format("Table %s does not exist", oldTable.getIndexTableName()));
        }

        if (tableManager.exists(newTable.getIndexTableName())) {
            throw new PrestoException(ACCUMULO_TABLE_EXISTS, format("Table %s already exists", newTable.getIndexTableName()));
        }

        if (!tableManager.exists(oldTable.getMetricsTableName())) {
            throw new PrestoException(ACCUMULO_TABLE_DNE, format("Table %s does not exist", oldTable.getMetricsTableName()));
        }

        if (tableManager.exists(newTable.getMetricsTableName())) {
            throw new PrestoException(ACCUMULO_TABLE_EXISTS, format("Table %s already exists", newTable.getMetricsTableName()));
        }

        tableManager.renameAccumuloTable(oldTable.getIndexTableName(), newTable.getIndexTableName());
        tableManager.renameAccumuloTable(oldTable.getMetricsTableName(), newTable.getMetricsTableName());
    }
118451
def change_numbering(self, rename_dict, inplace=False):
        
        output = self if inplace else self.copy()
        new_index = [rename_dict.get(key, key) for key in self.index]
        output.index = new_index
        if not inplace:
            return output
138504
def get_alter_table_sql(self, diff):
        
        sql = self._get_simple_alter_table_sql(diff)
        if sql is not False:
            return sql

        from_table = diff.from_table
        if not isinstance(from_table, Table):
            raise DBALException(
                "SQLite platform requires for the alter table the table diff "
                "referencing the original table"
            )

        table = from_table.clone()
        columns = OrderedDict()
        old_column_names = OrderedDict()
        new_column_names = OrderedDict()
        column_sql = []
        for column_name, column in table.get_columns().items():
            column_name = column_name.lower()
            columns[column_name] = column
            old_column_names[column_name] = column.get_quoted_name(self)
            new_column_names[column_name] = column.get_quoted_name(self)

        for column_name, column in diff.removed_columns.items():
            column_name = column_name.lower()
            if column_name in columns:
                del columns[column_name]
                del old_column_names[column_name]
                del new_column_names[column_name]

        for old_column_name, column in diff.renamed_columns.items():
            old_column_name = old_column_name.lower()
            if old_column_name in columns:
                del columns[old_column_name]

            columns[column.get_name().lower()] = column

            if old_column_name in new_column_names:
                new_column_names[old_column_name] = column.get_quoted_name(self)

        for old_column_name, column_diff in diff.changed_columns.items():
            if old_column_name in columns:
                del columns[old_column_name]

            columns[column_diff.column.get_name().lower()] = column_diff.column

            if old_column_name in new_column_names:
                new_column_names[old_column_name] = column_diff.column.get_quoted_name(
                    self
                )

        for column_name, column in diff.added_columns.items():
            columns[column_name.lower()] = column

        table_sql = []

        data_table = Table("__temp__" + table.get_name())
        new_table = Table(
            table.get_quoted_name(self),
            columns,
            self._get_primary_index_in_altered_table(diff),
            self._get_foreign_keys_in_altered_table(diff),
            table.get_options(),
        )
        new_table.add_option("alter", True)

        sql = self.get_pre_alter_table_index_foreign_key_sql(diff)
        sql.append(
            "CREATE TEMPORARY TABLE %s AS SELECT %s FROM %s"
            % (
                data_table.get_quoted_name(self),
                ", ".join(old_column_names.values()),
                table.get_quoted_name(self),
            )
        )
        sql.append(self.get_drop_table_sql(from_table))

        sql += self.get_create_table_sql(new_table)
        sql.append(
            "INSERT INTO %s (%s) SELECT %s FROM %s"
            % (
                new_table.get_quoted_name(self),
                ", ".join(new_column_names.values()),
                ", ".join(old_column_names.values()),
                data_table.get_name(),
            )
        )
        sql.append(self.get_drop_table_sql(data_table))

        sql += self.get_post_alter_table_index_foreign_key_sql(diff)

        return sql
923567
def drop_index_by_name(self, db_name, tbl_name, index_name, deleteData):
    
    self.send_drop_index_by_name(db_name, tbl_name, index_name, deleteData)
    return self.recv_drop_index_by_name()
1062156
def alter_table(table_name, options = {}) #:nodoc:
      table_name = table_name.to_s.downcase
      altered_table_name = "altered_#{table_name}"
      caller = lambda {|definition| yield definition if block_given?}

      transaction do
        # A temporary table might improve performance here, but
        # it doesn't seem to maintain indices across the whole move.
        move_table(table_name, altered_table_name,
          options)
        move_table(altered_table_name, table_name, &caller)
      end
    end
1037329
def rename_item(self, table_name, item_old_name, item_new_name):
        
        # define some helper methods:

        def put_together_if_list(item):
            """
            String joining function
            that doesn't break with None/np.nan
            """
            try:
                res = ":".join(item)
                return ":".join(item)
            except TypeError as ex:
                #print ex
                return item

        def replace_colon_delimited_value(df, col_name, old_value, new_value):
            """
            Col must contain list
            """
            count = 1
            for index, row in df[df[col_name].notnull()].iterrows():
                names_list = row[col_name]
                names_list = [name.strip() for name in names_list]
                try:
                    ind = names_list.index(old_value)
                except ValueError as ex:
                    count += 1
                    continue
                names_list[ind] = new_value
                df.loc[count, col_name] = names_list
                count += 1

        # initialize some things
        item_type = table_name
        ###col_name = item_type[:-1] + "_name"
        col_name = item_type[:-1]
        col_name_plural = col_name + "s"
        table_df = self.tables[item_type].df

        if item_old_name == '':
            # just add a new item
            self.add_item(table_name, {col_name: item_new_name}, item_new_name)
            return

        # rename item in its own table
        table_df.rename(index={item_old_name: item_new_name}, inplace=True)
        # rename in any parent/child tables
        for table_name in self.tables:
            df = self.tables[table_name].df
            col_names = df.columns
            # change anywhere col_name (singular, i.e. site) is found
            if col_name in col_names:
                df[col_name].where(df[col_name] != item_old_name, item_new_name, inplace=True)
                # change anywhere col_name (plural, i.e. sites) is found
            if col_name_plural in col_names:
                df[col_name_plural + "_list"] = df[col_name_plural].str.split(":")
                replace_colon_delimited_value(df, col_name_plural + "_list", item_old_name, item_new_name)
                df[col_name_plural] = df[col_name_plural + "_list"].apply(put_together_if_list)
                df.drop(col_name_plural + "_list", axis=1, inplace=True)
            self.tables[table_name].df = df