public function unApply($state, $schemaEditor)
    {
        // we
        $itemsToRun = [];

        // Phase 1 --
        /* @var $operation Operation */
        /** @var $newState ProjectState */
        $newState = $state;
        // we need to reverse the operations so that foreignkeys are removed
        // before model is destroyed
        foreach ($this->operations as $operation) {
            //Preserve new state from previous run to not tamper the same
            // state over all operations
            $newState = $newState->deepClone();
            $oldState = $newState->deepClone();
            $operation->updateState($newState);
            $operation->setAppLabel($this->getAppLabel());
            /*
             * we insert them in the reverse order so the last operation is
             * run first
             */
            array_unshift(
                $itemsToRun,
                [
                    'operation' => $operation,
                    'oldState' => $oldState,
                    'newState' => $newState,
                ]
            );
        }

        // Phase 2 -- Since we are un applying the old state is where we want
        // to go back to
        //   and the new state is where we are moving away from i.e
        //   we are moving from $newState to $oldState

        foreach ($itemsToRun as $runItem) {
            $schemaEditor->connection->beginTransaction();
            try {
                /** @var $operation Operation */
                $operation = $runItem['operation'];

                if (!$operation->isReducibleToSql()) {
                    $schemaEditor->addSql(
                        '-- MIGRATION NOW PERFORMS'.
                        ' OPERATION THAT CANNOT BE WRITTEN AS SQL:'
                    );
                }
                $schemaEditor->addSql(
                    sprintf(
                        '<fg=yellow>-- %s </>',
                        ucfirst($operation->getDescription())
                    )
                );

                if ($operation->isReducibleToSql()) {
                    $operation->databaseBackwards(
                        $schemaEditor,
                        $runItem['newState'],
                        $runItem['oldState']
                    );
                }
                $schemaEditor->connection->commit();
            } catch (\Exception $exception) {
                $schemaEditor->connection->rollBack();
                throw new CommandError($exception->getMessage());
            }
        }

        return $state;
    }
public function unApply($state, $schemaEditor)
    {
        // we
        $itemsToRun = [];

        // Phase 1 --
        /* @var $operation Operation */
        /** @var $newState ProjectState */
        $newState = $state;
        // we need to reverse the operations so that foreignkeys are removed
        // before model is destroyed
        foreach ($this->operations as $operation) {
            //Preserve new state from previous run to not tamper the same
            // state over all operations
            $newState = $newState->deepClone();
            $oldState = $newState->deepClone();
            $operation->updateState($newState);
            $operation->setAppLabel($this->getAppLabel());
            /*
             * we insert them in the reverse order so the last operation is
             * run first
             */
            array_unshift(
                $itemsToRun,
                [
                    'operation' => $operation,
                    'oldState' => $oldState,
                    'newState' => $newState,
                ]
            );
        }

        // Phase 2 -- Since we are un applying the old state is where we want
        // to go back to
        //   and the new state is where we are moving away from i.e
        //   we are moving from $newState to $oldState

        foreach ($itemsToRun as $runItem) {
            $schemaEditor->connection->beginTransaction();
            try {
                /** @var $operation Operation */
                $operation = $runItem['operation'];

                if (!$operation->isReducibleToSql()) {
                    $schemaEditor->addSql(
                        '-- MIGRATION NOW PERFORMS'.
                        ' OPERATION THAT CANNOT BE WRITTEN AS SQL:'
                    );
                }
                $schemaEditor->addSql(
                    sprintf(
                        '<fg=yellow>-- %s </>',
                        ucfirst($operation->getDescription())
                    )
                );

                if ($operation->isReducibleToSql()) {
                    $operation->databaseBackwards(
                        $schemaEditor,
                        $runItem['newState'],
                        $runItem['oldState']
                    );
                }
                $schemaEditor->connection->commit();
            } catch (\Exception $exception) {
                $schemaEditor->connection->rollBack();
                throw new CommandError($exception->getMessage());
            }
        }

        return $state;
    }
public function unApply ( $ state , $ schemaEditor ) { // we $ itemsToRun = [ ] ; // Phase 1 -- /* @var $operation Operation */ /** @var $newState ProjectState */ $ newState = $ state ; // we need to reverse the operations so that foreignkeys are removed // before model is destroyed foreach ( $ this -> operations as $ operation ) { //Preserve new state from previous run to not tamper the same // state over all operations $ newState = $ newState -> deepClone ( ) ; $ oldState = $ newState -> deepClone ( ) ; $ operation -> updateState ( $ newState ) ; $ operation -> setAppLabel ( $ this -> getAppLabel ( ) ) ; /*
             * we insert them in the reverse order so the last operation is
             * run first
             */ array_unshift ( $ itemsToRun , [ 'operation' => $ operation , 'oldState' => $ oldState , 'newState' => $ newState , ] ) ; } // Phase 2 -- Since we are un applying the old state is where we want // to go back to //   and the new state is where we are moving away from i.e //   we are moving from $newState to $oldState foreach ( $ itemsToRun as $ runItem ) { $ schemaEditor -> connection -> beginTransaction ( ) ; try { /** @var $operation Operation */ $ operation = $ runItem [ 'operation' ] ; if ( ! $ operation -> isReducibleToSql ( ) ) { $ schemaEditor -> addSql ( '-- MIGRATION NOW PERFORMS' . ' OPERATION THAT CANNOT BE WRITTEN AS SQL:' ) ; } $ schemaEditor -> addSql ( sprintf ( '<fg=yellow>-- %s </>' , ucfirst ( $ operation -> getDescription ( ) ) ) ) ; if ( $ operation -> isReducibleToSql ( ) ) { $ operation -> databaseBackwards ( $ schemaEditor , $ runItem [ 'newState' ] , $ runItem [ 'oldState' ] ) ; } $ schemaEditor -> connection -> commit ( ) ; } catch ( \ Exception $ exception ) { $ schemaEditor -> connection -> rollBack ( ) ; throw new CommandError ( $ exception -> getMessage ( ) ) ; } } return $ state ; }
Takes a project_state representing all migrations prior to this one
and a schema for a live database and applies
the migration in a reverse order.

The backwards migration process consists of two phases:
1. The intermediate states from right before the first until right
after the last operation inside this migration are preserved.
2. The operations are applied in reverse order using the states
recorded in step 1.

@param ProjectState $state
@param SchemaEditor $schemaEditor

@return mixed

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>

@throws \Eddmash\PowerOrm\Exception\NotImplemented
@throws \Exception
Takes a project_state representing all migrations prior to this one and a schema for a live database and applies the migration in a reverse order .