src/Table.php
public function upgrade(Table $old_table)
        {
            $old_columns = $old_table->getColumns();
            $new_columns = $this->getColumns();

            $added_columns = \array_diff_key($new_columns, $old_columns);
            $altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
            $dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));

            /** @var RawQuery[] $queries */
            $queries = [];
            foreach ($added_columns as $details) {
                $queries[] = $this->getAddColumnQuery($details);
            }

            foreach ($queries as $query) {
                if ($query instanceof QueryInterface) {
                    Statement::getPreparedStatement($query)->execute();
                }
            }

            $this->migrateData($old_table);

            $queries = [];
            foreach ($altered_columns as $column => $details) {
                if (in_array($column, $dropped_columns)) continue;

                $queries[] = $this->getAlterColumnQuery($new_columns[$column]);
                $queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
            }
            foreach ($dropped_columns as $details) {
                $queries[] = $this->getDropColumnQuery($details);
            }
            foreach ($queries as $query) {
                if ($query instanceof RawQuery) {
                    Statement::getPreparedStatement($query)->execute();
                }
            }
        }
public function upgrade(Table $old_table)
        {
            $old_columns = $old_table->getColumns();
            $new_columns = $this->getColumns();

            $added_columns = \array_diff_key($new_columns, $old_columns);
            $altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
            $dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));

            /** @var RawQuery[] $queries */
            $queries = [];
            foreach ($added_columns as $details) {
                $queries[] = $this->getAddColumnQuery($details);
            }

            foreach ($queries as $query) {
                if ($query instanceof QueryInterface) {
                    Statement::getPreparedStatement($query)->execute();
                }
            }

            $this->migrateData($old_table);

            $queries = [];
            foreach ($altered_columns as $column => $details) {
                if (in_array($column, $dropped_columns)) continue;

                $queries[] = $this->getAlterColumnQuery($new_columns[$column]);
                $queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
            }
            foreach ($dropped_columns as $details) {
                $queries[] = $this->getDropColumnQuery($details);
            }
            foreach ($queries as $query) {
                if ($query instanceof RawQuery) {
                    Statement::getPreparedStatement($query)->execute();
                }
            }
        }
public function upgrade ( Table $ old_table ) { $ old_columns = $ old_table -> getColumns ( ) ; $ new_columns = $ this -> getColumns ( ) ; $ added_columns = \ array_diff_key ( $ new_columns , $ old_columns ) ; $ altered_columns = Tools :: array_diff_recursive ( $ old_columns , $ new_columns ) ; $ dropped_columns = \ array_keys ( array_diff_key ( $ old_columns , $ new_columns ) ) ; /** @var RawQuery[] $queries */ $ queries = [ ] ; foreach ( $ added_columns as $ details ) { $ queries [ ] = $ this -> getAddColumnQuery ( $ details ) ; } foreach ( $ queries as $ query ) { if ( $ query instanceof QueryInterface ) { Statement :: getPreparedStatement ( $ query ) -> execute ( ) ; } } $ this -> migrateData ( $ old_table ) ; $ queries = [ ] ; foreach ( $ altered_columns as $ column => $ details ) { if ( in_array ( $ column , $ dropped_columns ) ) continue ; $ queries [ ] = $ this -> getAlterColumnQuery ( $ new_columns [ $ column ] ) ; $ queries [ ] = $ this -> getAlterColumnDefaultQuery ( $ new_columns [ $ column ] ) ; } foreach ( $ dropped_columns as $ details ) { $ queries [ ] = $ this -> getDropColumnQuery ( $ details ) ; } foreach ( $ queries as $ query ) { if ( $ query instanceof RawQuery ) { Statement :: getPreparedStatement ( $ query ) -> execute ( ) ; } } }
Perform upgrade for a table, by comparing one table to an old version
of the same table

@param Table $old_table
Perform upgrade for a table by comparing one table to an old version of the same table