LazyRecord\Migration\MigrationRunner::runDowngrade PHP Метод

runDowngrade() публичный Метод

Run downgrade scripts.
public runDowngrade ( Connection $conn, BaseDriver $driver, array $scripts = null, $steps = 1 )
$conn LazyRecord\Connection
$driver SQLBuilder\Driver\BaseDriver
$scripts array
    public function runDowngrade(Connection $conn, BaseDriver $driver, array $scripts = null, $steps = 1)
    {
        if (!$scripts) {
            $scripts = $this->getDowngradeScripts($conn, $driver);
        }
        $this->logger->info('Found ' . count($scripts) . ' migration scripts to run downgrade!');
        while ($steps--) {
            // downgrade a migration one at one time.
            if ($script = array_pop($scripts)) {
                $this->logger->info("Running {$script}::downgrade");
                $migration = new $script($conn, $driver, $this->logger);
                $migration->downgrade();
                if ($nextScript = end($scripts)) {
                    $id = $nextScript::getId();
                    $this->updateLastMigrationId($conn, $driver, $id);
                    $this->logger->info("Updated migration timestamp to {$id}.");
                }
            }
        }
    }

Usage Example

 public function execute()
 {
     $dsId = $this->getCurrentDataSourceId();
     $runner = new MigrationRunner($dsId);
     $runner->load($this->options->{'script-dir'} ?: 'db/migrations');
     $this->logger->info('Running migration scripts to downgrade...');
     $runner->runDowngrade();
     $this->logger->info('Done.');
 }
All Usage Examples Of LazyRecord\Migration\MigrationRunner::runDowngrade