/*
This automatically migrates any records from the previous namespace to the current namespace, since the
table names actually contain these.
485384
public function requireDefaultRecords() {

        parent::requireDefaultRecords();

        // The tables to migrate.

        $from = 'SilverStripeAustralia\ContentServiceAssets\ContentServiceAsset';
        $to = 'Symbiote\ContentServiceAssets\ContentServiceAsset';
        $escaped = 'Symbiote\\\\ContentServiceAssets\\\\ContentServiceAsset';

        // This only ever needs to run once, so we need to do an efficient check here.

        if(
            !\DB::query("SELECT EXISTS(SELECT 1 FROM \"{$to}\" LIMIT 1);")->value() &&
            \ClassInfo::hasTable($from) &&
            \DB::query("SELECT EXISTS(SELECT 1 FROM \"{$from}\" LIMIT 1);")->value()
        ) {

            // Copy the records across, and make sure the class name is correct.

            \DB::query("INSERT INTO \"{$to}\" SELECT * FROM \"{$from}\";");
            \DB::query("UPDATE \"{$to}\" SET ClassName = '{$escaped}';");
        }
    }
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());
    }
540993
@Deprecated
    public String registerTableOverride(String oldTable, String newTable) {
        return internalNameMapping.registerTableOverride(oldTable, newTable);
    }
204762
public void ensureNamespace(String schema)
    {
        try {
            // If the table schema is not "default" and the namespace does not exist, create it
            if (!schema.equals(DEFAULT) && !connector.namespaceOperations().exists(schema)) {
                connector.namespaceOperations().create(schema);
            }
        }
        catch (AccumuloException | AccumuloSecurityException e) {
            throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to check for existence or create Accumulo namespace", e);
        }
        catch (NamespaceExistsException e) {
            // Suppress race condition between test for existence and creation
            LOG.warn("NamespaceExistsException suppressed when creating " + schema);
        }
    }
85542
public String getNameSpace() {
        if (nameSpace == null) {
            nameSpace = new StringBuilder().append(catalog).append(".").append(table).toString();
        }
        return nameSpace;

    }
995333
def rename_table(dbconn, original, new):
    
    cur = dbconn.cursor()
    cur.execute("ALTER TABLE '{original}' RENAME TO '{new}'".format(original=original, new=new))
302163
def migrate(pool, from_connection, to_connection):
    
    f = connect_database(from_connection)
    t = connect_database(to_connection)

    if isinstance(f, ProjectDB):
        for each in f.get_all():
            each = unicode_obj(each)
            logging.info("projectdb: %s", each['name'])
            t.drop(each['name'])
            t.insert(each['name'], each)
    elif isinstance(f, TaskDB):
        pool = Pool(pool)
        pool.map(
            lambda x, f=from_connection, t=to_connection: taskdb_migrating(x, f, t),
            f.projects)
    elif isinstance(f, ResultDB):
        pool = Pool(pool)
        pool.map(
            lambda x, f=from_connection, t=to_connection: resultdb_migrating(x, f, t),
            f.projects)
1108259
def from_(self, table, alias=None):
        
        if isinstance(table, str):
            table = [[table, alias]]
        self.raw_tables = table
        return self
1242759
public function migrateUp( $levels = NULL )
    {
        if ( NULL !== $levels )
        {
            $this->levels = $levels;
        }
        
        $newMigrations = $this->getNewMigrations( );
        
        $i = 0;
        
        if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $newMigrations ) )
        {
            $this->levels = count( $newMigrations );
        }
        
        while ( $i < $this->levels )
        {
            $class = $this->migrationNamespace . '\\' . $newMigrations[ $i ];
            
            if ( !class_exists( $class ) )
            {
                if ( !array_search( 'RawPHP\\RawMigrator\\Migrations\\', $this->namespaces, TRUE ) )
                {
                    $this->namespaces[] = 'RawPHP\\RawMigrator\\Migrations\\';
                }
                
                foreach( $this->namespaces as $ns )
                {
                    $cls = $ns . $newMigrations[ $i ];
                    
                    if ( class_exists( $cls ) )
                    {
                        $class = $cls;
                        
                        break;
                    }
                }
                
                if ( NULL === $class )
                {
                    throw new MigrationException( 'Migration class: ' . $class . ' - not found' );
                }
            }
            
            $migration = new $class( );
            
            $method = new \ReflectionMethod( $class, 'migrateUp' );
            
            // run migrateUp
            if ( $class === $method->getdeclaringClass()->name )
            {
                $migration->migrateUp( $this->db );
                
                $this->_addMigrationRecord( $class );
            }
            else
            {
                $method = new \ReflectionMethod( $class, 'safeMigrateUp' );
                
                if ( $class === $method->getDeclaringClass()->name )
                {
                    try
                    {
                        $this->db->startTransaction( );
                        
                        // turn off auto commit
                        $this->db->setTransactionAutocommit( FALSE );
                        
                        // run safeMigrateUp
                        $migration->safeMigrateUp( $this->db );
                        
                        // update migrations table with the new applied migration
                        $this->_addMigrationRecord( $class );
                        
                        // commit transaction
                        $this->db->commitTransaction( );
                    }
                    catch ( Exception $e )
                    {
                        // roleback transaction
                        $this->db->rollbackTransaction( );
                        
                        throw $e;
                    }
                }
            }
            
            $i++;
            
            if ( $this->levels === $i )
            {
                $this->doAction( self::ON_MIGRATE_UP_ACTION );
                
                return;
            }
        }
    }
1156538
protected void migrateSchema() {

        try {

            Connection connection = dataSource.getConnection();
            try {

                beforeSchemaMigration(connection);

                SchemaUpdater updater = new SchemaUpdater(connection, tableName, serializer);
                if (!updater.doesTableExist()) {
                    updater.migrateToVersion1();
                }
                if (updater.isSchemaVersion1()) {
                    updater.migrateToVersion2();
                }

                afterSchemaMigration(connection);


            } finally {
                DbUtils.closeQuietly(connection);
            }

        } catch (SQLException e) {
            throw new IllegalStateException("Failed to migrate the database schema", e);
        }

    }
553093
private void ProcessNextStep() {

        switch (iSelectionStep) {

            case SELECT_SOURCE_CATALOG :
            case SELECT_DEST_CATALOG :
                if (CatalogToSelect()) {
                    fMain.show();

                    return;
                }
                break;

            case SELECT_DEST_SCHEMA :
            case SELECT_SOURCE_SCHEMA :
                if (SchemaToSelect()) {
                    fMain.show();

                    return;
                }
                break;

            case SELECT_SOURCE_TABLES :
                if (iTransferMode == TRFM_TRANSFER) {
                    bStart.setLabel("Start Transfer");
                } else if (iTransferMode == TRFM_DUMP) {
                    bStart.setLabel("Start Dump");
                } else if (iTransferMode == TRFM_RESTORE) {
                    bStart.setLabel("Start Restore");
                }

                bStart.invalidate();
                bStart.setEnabled(false);
                lTable.setMultipleMode(false);
                RefreshMainDisplay();
                break;

            default :
                break;
        }
    }
88179
private void resize() {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "resize", table.length);

    Entry[] newTable = new Entry[table.length + (table.length / 2)];

    /* We have to walk the entire SchemaSet, rehashing each Entry and putting */
    /* it in its new home. As contains() may be running at the same time, we  */
    /* have to create a new Entry instance for each.                          */
    for (int i = 0; i < table.length; i++) {
      Entry ent = table[i];
      Entry newEntry;
      int j;
      while (ent != null) {
        j = hashToTable(ent.schemaId, newTable);
        newEntry = new Entry(ent.schemaId, newTable[j]);
        newTable[j] = newEntry;
        ent = ent.next;
      }
    }

    /* Now replace the old table with the new one. */
    table = newTable;

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "resize", table.length);
  }
1178486
def tablerename(tablename, newtablename):
    
    t = table(tablename, ack=False)
    t.rename(newtablename)
220086
public function renameTable($oldName, $newName)
    {
        if (!$this->hasTable($oldName)) {
            throw SchemaException::schemaTableDoesNotExist($this->getName(), $oldName);
        }

        if ($this->hasTable($newName)) {
            throw SchemaException::schemaTableAlreadyExists($this->getName(), $newName);
        }

        $this->tables[$oldName]->setName($newName);
        $this->tables[$newName] = $this->tables[$oldName];

        unset($this->tables[$oldName]);
    }
614725
final Collection<ServiceNamespace> retainAndGetNamespaces() {
        PartitionReplicationEvent event = new PartitionReplicationEvent(partitionId, 0);
        Collection<FragmentedMigrationAwareService> services = nodeEngine.getServices(FragmentedMigrationAwareService.class);

        Set<ServiceNamespace> namespaces = new HashSet<>();
        for (FragmentedMigrationAwareService service : services) {
            Collection<ServiceNamespace> serviceNamespaces = service.getAllServiceNamespaces(event);
            if (serviceNamespaces != null) {
                namespaces.addAll(serviceNamespaces);
            }
        }
        namespaces.add(NonFragmentedServiceNamespace.INSTANCE);

        PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
        replicaManager.retainNamespaces(partitionId, namespaces);
        return replicaManager.getNamespaces(partitionId);
    }
319044
def migrate_tables(tables, engine_name=None):
    
    from alembic.migration import MigrationContext
    engine = engine_manager[engine_name]
    mc = MigrationContext.configure(engine.session().connection)
    script =  get_migrate_script(mc, tables, engine.metadata)
    run_migrate_script(mc, script)
601653
public synchronized void refreshNamespaces() {
		/*
		 * cache namespaces
		 */
		if (this.namespaceCache == null) {
			this.namespaceCache = new TreeMap<String, Namespace>();
			Node[] nodes = client.getNodes();
			for (Node node : nodes) {
				try {
					String namespaceString = Info.request(getInfoPolicy(), node, "namespaces");
					if (!namespaceString.isEmpty()) {
						String[] namespaceList = namespaceString.split(";");
						for (String namespace : namespaceList) {
							Namespace ns = this.namespaceCache.get(namespace);
							if (ns == null) {
								ns = new Namespace(namespace);
								this.namespaceCache.put(namespace, ns);
							}
							refreshNamespaceData(node, ns);
						}
					}
				} catch (AerospikeException e) {
					log.error("Error geting Namespaces ", e);
				}

			}
		}
	}