private function alterTableMigrate(array $alterDef, array $options = []) {
        $table = $alterDef['name'];
        $currentDef = $this->fetchTableDef($table);

        // Merge the table definitions if we aren't dropping stuff.
        if (!self::val(Db::OPTION_DROP, $options)) {
            $tableDef = $this->mergeTableDefs($currentDef, $alterDef);
        } else {
            $tableDef = $alterDef['def'];
        }

        // Drop all of the indexes on the current table.
        foreach (self::val('indexes', $currentDef, []) as $indexDef) {
            if (self::val('type', $indexDef, Db::INDEX_IX) === Db::INDEX_IX) {
                $this->dropIndex($indexDef['name']);
            }
        }

        $tmpTable = $table.'_'.time();

        // Rename the current table.
        $this->renameTable($table, $tmpTable);

        // Create the new table.
        $this->createTableDb($tableDef, $options);

        // Figure out the columns that we can insert.
        $columns = array_keys(array_intersect_key($tableDef['columns'], $currentDef['columns']));

        // Build the insert/select statement.
        $sql = 'insert into '.$this->prefixTable($table)."\n".
            $this->bracketList($columns, '`')."\n".
            $this->buildSelect($tmpTable, [], ['columns' => $columns]);

        $this->queryDefine($sql);

        // Drop the temp table.
        $this->dropTable($tmpTable);
    }
private function alterTableMigrate(array $alterDef, array $options = []) {
        $table = $alterDef['name'];
        $currentDef = $this->fetchTableDef($table);

        // Merge the table definitions if we aren't dropping stuff.
        if (!self::val(Db::OPTION_DROP, $options)) {
            $tableDef = $this->mergeTableDefs($currentDef, $alterDef);
        } else {
            $tableDef = $alterDef['def'];
        }

        // Drop all of the indexes on the current table.
        foreach (self::val('indexes', $currentDef, []) as $indexDef) {
            if (self::val('type', $indexDef, Db::INDEX_IX) === Db::INDEX_IX) {
                $this->dropIndex($indexDef['name']);
            }
        }

        $tmpTable = $table.'_'.time();

        // Rename the current table.
        $this->renameTable($table, $tmpTable);

        // Create the new table.
        $this->createTableDb($tableDef, $options);

        // Figure out the columns that we can insert.
        $columns = array_keys(array_intersect_key($tableDef['columns'], $currentDef['columns']));

        // Build the insert/select statement.
        $sql = 'insert into '.$this->prefixTable($table)."\n".
            $this->bracketList($columns, '`')."\n".
            $this->buildSelect($tmpTable, [], ['columns' => $columns]);

        $this->queryDefine($sql);

        // Drop the temp table.
        $this->dropTable($tmpTable);
    }
private function alterTableMigrate ( array $ alterDef , array $ options = [ ] ) { $ table = $ alterDef [ 'name' ] ; $ currentDef = $ this -> fetchTableDef ( $ table ) ; // Merge the table definitions if we aren't dropping stuff. if ( ! self :: val ( Db :: OPTION_DROP , $ options ) ) { $ tableDef = $ this -> mergeTableDefs ( $ currentDef , $ alterDef ) ; } else { $ tableDef = $ alterDef [ 'def' ] ; } // Drop all of the indexes on the current table. foreach ( self :: val ( 'indexes' , $ currentDef , [ ] ) as $ indexDef ) { if ( self :: val ( 'type' , $ indexDef , Db :: INDEX_IX ) === Db :: INDEX_IX ) { $ this -> dropIndex ( $ indexDef [ 'name' ] ) ; } } $ tmpTable = $ table . '_' . time ( ) ; // Rename the current table. $ this -> renameTable ( $ table , $ tmpTable ) ; // Create the new table. $ this -> createTableDb ( $ tableDef , $ options ) ; // Figure out the columns that we can insert. $ columns = array_keys ( array_intersect_key ( $ tableDef [ 'columns' ] , $ currentDef [ 'columns' ] ) ) ; // Build the insert/select statement. $ sql = 'insert into ' . $ this -> prefixTable ( $ table ) . "\n" . $ this -> bracketList ( $ columns , '`' ) . "\n" . $ this -> buildSelect ( $ tmpTable , [ ] , [ 'columns' => $ columns ] ) ; $ this -> queryDefine ( $ sql ) ; // Drop the temp table. $ this -> dropTable ( $ tmpTable ) ; }
Alter a table by creating a new table and copying the old table's data to it.

@param array $alterDef The new definition.
@param array $options An array of options for the migration.
Alter a table by creating a new table and copying the old table s data to it .