src/Schema/AbstractTable.php
protected function normalizeSchema(bool $withForeignKeys = true)
    {
        // To make sure that no pre-sync modifications will be reflected on current table
        $target = clone $this;

        // declare all FKs dropped on tables scheduled for removal
        if ($this->status === self::STATUS_DECLARED_DROPPED) {
            foreach ($target->getForeignKeys() as $fk) {
                $target->current->forgerForeignKey($fk);
            }
        }

        /*
         * In cases where columns are removed we have to automatically remove related indexes and
         * foreign keys.
         */
        foreach ($this->getComparator()->droppedColumns() as $column) {
            foreach ($target->getIndexes() as $index) {
                if (in_array($column->getName(), $index->getColumns())) {
                    $target->current->forgetIndex($index);
                }
            }

            foreach ($target->getForeignKeys() as $foreign) {
                if ($column->getName() == $foreign->getColumn()) {
                    $target->current->forgerForeignKey($foreign);
                }
            }
        }

        //We also have to adjusts indexes and foreign keys
        foreach ($this->getComparator()->alteredColumns() as $pair) {
            /**
             * @var AbstractColumn $initial
             * @var AbstractColumn $name
             */
            list($name, $initial) = $pair;

            foreach ($target->getIndexes() as $index) {
                if (in_array($initial->getName(), $index->getColumns())) {
                    $columns = $index->getColumns();

                    //Replacing column name
                    foreach ($columns as &$column) {
                        if ($column == $initial->getName()) {
                            $column = $name->getName();
                        }

                        unset($column);
                    }

                    $targetIndex = $target->initial->findIndex($index->getColumns());
                    if (!empty($targetIndex)) {
                        //Target index got renamed or removed.
                        $targetIndex->columns($columns);
                    }

                    $index->columns($columns);
                }
            }

            foreach ($target->getForeignKeys() as $foreign) {
                if ($initial->getName() == $foreign->getColumn()) {
                    $foreign->column($name->getName());
                }
            }
        }

        if (!$withForeignKeys) {
            foreach ($this->getComparator()->addedForeignKeys() as $foreign) {
                //Excluding from creation
                $target->current->forgerForeignKey($foreign);
            }
        }

        return $target;
    }
protected function normalizeSchema(bool $withForeignKeys = true)
    {
        // To make sure that no pre-sync modifications will be reflected on current table
        $target = clone $this;

        // declare all FKs dropped on tables scheduled for removal
        if ($this->status === self::STATUS_DECLARED_DROPPED) {
            foreach ($target->getForeignKeys() as $fk) {
                $target->current->forgerForeignKey($fk);
            }
        }

        /*
         * In cases where columns are removed we have to automatically remove related indexes and
         * foreign keys.
         */
        foreach ($this->getComparator()->droppedColumns() as $column) {
            foreach ($target->getIndexes() as $index) {
                if (in_array($column->getName(), $index->getColumns())) {
                    $target->current->forgetIndex($index);
                }
            }

            foreach ($target->getForeignKeys() as $foreign) {
                if ($column->getName() == $foreign->getColumn()) {
                    $target->current->forgerForeignKey($foreign);
                }
            }
        }

        //We also have to adjusts indexes and foreign keys
        foreach ($this->getComparator()->alteredColumns() as $pair) {
            /**
             * @var AbstractColumn $initial
             * @var AbstractColumn $name
             */
            list($name, $initial) = $pair;

            foreach ($target->getIndexes() as $index) {
                if (in_array($initial->getName(), $index->getColumns())) {
                    $columns = $index->getColumns();

                    //Replacing column name
                    foreach ($columns as &$column) {
                        if ($column == $initial->getName()) {
                            $column = $name->getName();
                        }

                        unset($column);
                    }

                    $targetIndex = $target->initial->findIndex($index->getColumns());
                    if (!empty($targetIndex)) {
                        //Target index got renamed or removed.
                        $targetIndex->columns($columns);
                    }

                    $index->columns($columns);
                }
            }

            foreach ($target->getForeignKeys() as $foreign) {
                if ($initial->getName() == $foreign->getColumn()) {
                    $foreign->column($name->getName());
                }
            }
        }

        if (!$withForeignKeys) {
            foreach ($this->getComparator()->addedForeignKeys() as $foreign) {
                //Excluding from creation
                $target->current->forgerForeignKey($foreign);
            }
        }

        return $target;
    }
protected function normalizeSchema ( bool $ withForeignKeys = true ) { // To make sure that no pre-sync modifications will be reflected on current table $ target = clone $ this ; // declare all FKs dropped on tables scheduled for removal if ( $ this -> status === self :: STATUS_DECLARED_DROPPED ) { foreach ( $ target -> getForeignKeys ( ) as $ fk ) { $ target -> current -> forgerForeignKey ( $ fk ) ; } } /*
         * In cases where columns are removed we have to automatically remove related indexes and
         * foreign keys.
         */ foreach ( $ this -> getComparator ( ) -> droppedColumns ( ) as $ column ) { foreach ( $ target -> getIndexes ( ) as $ index ) { if ( in_array ( $ column -> getName ( ) , $ index -> getColumns ( ) ) ) { $ target -> current -> forgetIndex ( $ index ) ; } } foreach ( $ target -> getForeignKeys ( ) as $ foreign ) { if ( $ column -> getName ( ) == $ foreign -> getColumn ( ) ) { $ target -> current -> forgerForeignKey ( $ foreign ) ; } } } //We also have to adjusts indexes and foreign keys foreach ( $ this -> getComparator ( ) -> alteredColumns ( ) as $ pair ) { /**
             * @var AbstractColumn $initial
             * @var AbstractColumn $name
             */ list ( $ name , $ initial ) = $ pair ; foreach ( $ target -> getIndexes ( ) as $ index ) { if ( in_array ( $ initial -> getName ( ) , $ index -> getColumns ( ) ) ) { $ columns = $ index -> getColumns ( ) ; //Replacing column name foreach ( $ columns as & $ column ) { if ( $ column == $ initial -> getName ( ) ) { $ column = $ name -> getName ( ) ; } unset ( $ column ) ; } $ targetIndex = $ target -> initial -> findIndex ( $ index -> getColumns ( ) ) ; if ( ! empty ( $ targetIndex ) ) { //Target index got renamed or removed. $ targetIndex -> columns ( $ columns ) ; } $ index -> columns ( $ columns ) ; } } foreach ( $ target -> getForeignKeys ( ) as $ foreign ) { if ( $ initial -> getName ( ) == $ foreign -> getColumn ( ) ) { $ foreign -> column ( $ name -> getName ( ) ) ; } } } if ( ! $ withForeignKeys ) { foreach ( $ this -> getComparator ( ) -> addedForeignKeys ( ) as $ foreign ) { //Excluding from creation $ target -> current -> forgerForeignKey ( $ foreign ) ; } } return $ target ; }
Ensure that no wrong indexes left in table. This method will create AbstracTable
copy in order to prevent cross modifications.

@param bool $withForeignKeys
@return AbstractTable
Ensure that no wrong indexes left in table . This method will create AbstracTable copy in order to prevent cross modifications .