public function actionDown(RequestApplicationInterface $app, $limit = 1)
    {
        if ($limit === 'all') {
            $limit = null;
        } else {
            $limit = (int)$limit;
            if ($limit < 1) {
                throw new Exception('The step argument must be greater than 0.');
            }
        }

        return $this->getMigrationHistory($limit)->then(
            function($migrations) {
                if (empty($migrations)) {
                    $this->stdout("No migration has been done before.\n", Console::FG_YELLOW);

                    return true;
                }
                $migrations = array_keys($migrations);
                $n = count($migrations);
                $this->stdout("Total $n " . ($n === 1 ? 'migration' : 'migrations') . " to be reverted:\n", Console::FG_YELLOW);
                foreach ($migrations as $migration) {
                    $this->stdout("\t$migration\n");
                }
                $this->stdout("\n");

                $reverted = 0;

                return $this->confirm('Revert the above ' . ($n === 1 ? 'migration' : 'migrations') . '?')->then(
                    function() use ($migrations, $n, &$reverted) {
                        $promises = [];
                        foreach ($migrations as $migration) {
                            $promises[] = $this->migrateDown($migration)->thenLazy(
                                function() use (&$reverted) {
                                    $reverted++;
                                    return true;
                                },
                                function($error = null) use ($reverted, $n) {
                                    $this->stdout("\n$reverted from $n " . ($reverted === 1 ? 'migration was' : 'migrations were') . " reverted.\n", Console::FG_RED);
                                    $this->stdout("\nMigration failed. The rest of the migrations are canceled.\n", Console::FG_RED);
                                    return reject($error);
                                }
                            );
                        }
                        return allInOrder($promises)->then(
                            function() use ($n) {
                                $this->stdout("\n$n " . ($n === 1 ? 'migration was' : 'migrations were') . " reverted.\n", Console::FG_GREEN);
                                $this->stdout("\nMigrated down successfully.\n", Console::FG_GREEN);
                            }
                        );
                    }
                );
            }
        );
    }
public function actionDown(RequestApplicationInterface $app, $limit = 1)
    {
        if ($limit === 'all') {
            $limit = null;
        } else {
            $limit = (int)$limit;
            if ($limit < 1) {
                throw new Exception('The step argument must be greater than 0.');
            }
        }

        return $this->getMigrationHistory($limit)->then(
            function($migrations) {
                if (empty($migrations)) {
                    $this->stdout("No migration has been done before.\n", Console::FG_YELLOW);

                    return true;
                }
                $migrations = array_keys($migrations);
                $n = count($migrations);
                $this->stdout("Total $n " . ($n === 1 ? 'migration' : 'migrations') . " to be reverted:\n", Console::FG_YELLOW);
                foreach ($migrations as $migration) {
                    $this->stdout("\t$migration\n");
                }
                $this->stdout("\n");

                $reverted = 0;

                return $this->confirm('Revert the above ' . ($n === 1 ? 'migration' : 'migrations') . '?')->then(
                    function() use ($migrations, $n, &$reverted) {
                        $promises = [];
                        foreach ($migrations as $migration) {
                            $promises[] = $this->migrateDown($migration)->thenLazy(
                                function() use (&$reverted) {
                                    $reverted++;
                                    return true;
                                },
                                function($error = null) use ($reverted, $n) {
                                    $this->stdout("\n$reverted from $n " . ($reverted === 1 ? 'migration was' : 'migrations were') . " reverted.\n", Console::FG_RED);
                                    $this->stdout("\nMigration failed. The rest of the migrations are canceled.\n", Console::FG_RED);
                                    return reject($error);
                                }
                            );
                        }
                        return allInOrder($promises)->then(
                            function() use ($n) {
                                $this->stdout("\n$n " . ($n === 1 ? 'migration was' : 'migrations were') . " reverted.\n", Console::FG_GREEN);
                                $this->stdout("\nMigrated down successfully.\n", Console::FG_GREEN);
                            }
                        );
                    }
                );
            }
        );
    }
public function actionDown ( RequestApplicationInterface $ app , $ limit = 1 ) { if ( $ limit === 'all' ) { $ limit = null ; } else { $ limit = ( int ) $ limit ; if ( $ limit < 1 ) { throw new Exception ( 'The step argument must be greater than 0.' ) ; } } return $ this -> getMigrationHistory ( $ limit ) -> then ( function ( $ migrations ) { if ( empty ( $ migrations ) ) { $ this -> stdout ( "No migration has been done before.\n" , Console :: FG_YELLOW ) ; return true ; } $ migrations = array_keys ( $ migrations ) ; $ n = count ( $ migrations ) ; $ this -> stdout ( "Total $n " . ( $ n === 1 ? 'migration' : 'migrations' ) . " to be reverted:\n" , Console :: FG_YELLOW ) ; foreach ( $ migrations as $ migration ) { $ this -> stdout ( "\t$migration\n" ) ; } $ this -> stdout ( "\n" ) ; $ reverted = 0 ; return $ this -> confirm ( 'Revert the above ' . ( $ n === 1 ? 'migration' : 'migrations' ) . '?' ) -> then ( function ( ) use ( $ migrations , $ n , & $ reverted ) { $ promises = [ ] ; foreach ( $ migrations as $ migration ) { $ promises [ ] = $ this -> migrateDown ( $ migration ) -> thenLazy ( function ( ) use ( & $ reverted ) { $ reverted ++ ; return true ; } , function ( $ error = null ) use ( $ reverted , $ n ) { $ this -> stdout ( "\n$reverted from $n " . ( $ reverted === 1 ? 'migration was' : 'migrations were' ) . " reverted.\n" , Console :: FG_RED ) ; $ this -> stdout ( "\nMigration failed. The rest of the migrations are canceled.\n" , Console :: FG_RED ) ; return reject ( $ error ) ; } ) ; } return allInOrder ( $ promises ) -> then ( function ( ) use ( $ n ) { $ this -> stdout ( "\n$n " . ( $ n === 1 ? 'migration was' : 'migrations were' ) . " reverted.\n" , Console :: FG_GREEN ) ; $ this -> stdout ( "\nMigrated down successfully.\n" , Console :: FG_GREEN ) ; } ) ; } ) ; } ) ; }
Downgrades the application by reverting old migrations.

For example,

```
console migrate/down     # revert the last migration
console migrate/down 3   # revert the last 3 migrations
console migrate/down all # revert all migrations
```

@param RequestApplicationInterface $app
@param int|string                  $limit the number of migrations to be reverted. Defaults to 1,
meaning the last applied migration will be reverted. When value is "all", all migrations will be reverted.
@return ExtendedPromiseInterface
@throws Exception if the number of the steps specified is less than 1.
Downgrades the application by reverting old migrations .