/** * Rollback the last migration operation. * * @param array|string $paths * @param array $options * @return array */ public function rollback($paths = [], array $options = []) { $this->notes = []; $rolledBack = []; // We want to pull in the last batch of migrations that ran on the previous // migration operation. We'll then reverse those migrations and run each // of them "down" to reverse the last migration "operation" which ran. if (($steps = Arr::get($options, 'step', 0)) > 0) { $migrations = $this->repository->getMigrations($steps); } else { $migrations = $this->repository->getLast(); } $count = count($migrations); $files = $this->getMigrationFiles($paths); if ($count === 0) { $this->note('<info>Nothing to rollback.</info>'); } else { // Next we will run through all of the migrations and call the "down" method // which will reverse each migration in order. This getLast method on the // repository already returns these migration's names in reverse order. $this->requireFiles($files); foreach ($migrations as $migration) { $rolledBack[] = $files[$migration->migration]; $this->runDown($files[$migration->migration], (object) $migration, Arr::get($options, 'pretend', false)); } } return $rolledBack; }
/** * Rollback the last migration operation. * * @param bool $pretend * @return int */ public function rollback($pretend = false) { $this->notes = array(); // We want to pull in the last batch of migrations that ran on the previous // migration operation. We'll then reverse those migrations and run each // of them "down" to reverse the last migration "operation" which ran. $migrations = $this->repository->getLast(); if (count($migrations) == 0) { $this->note('<info>Nothing to rollback.</info>'); return count($migrations); } // We need to reverse these migrations so that they are "downed" in reverse // to what they run on "up". It lets us backtrack through the migrations // and properly reverse the entire database schema operation that ran. foreach ($migrations as $migration) { $this->runDown((object) $migration, $pretend); } return count($migrations); }
/** * Rollback the last migration operation. * * @param bool $pretend * * @return int */ public function rollback($pretend = false) { if (!$this->repository->repositoryExists()) { $this->note('<info>Nothing to rollback.</info>'); return 0; } $this->notes = []; $this->batch->validate(); $defined = array_reverse($this->batch->getExpanded()); // We want to pull in the last batch of migrations that ran on the // previous migration operation. We'll then reverse those migrations and // run each of them "down" to reverse the last migration "operation" // which ran. $migrations = $this->repository->getLast(); if (count($migrations) === 0) { $this->note('<info>Nothing to rollback.</info>'); return count($migrations); } // We need to reverse these migrations so that they are "downed" in // reverse to what they run on "up". It lets us backtrack through the // migrations and properly reverse the entire database schema operation // that ran. // // For structured migrations, we have to do some additional magic to // figure out the right order in which migrations should be rolled-back // since a simple sort by name won't do. $processedMigrations = []; foreach ($migrations as $migration) { $processedMigrations[$migration->migration] = $migration; } foreach ($defined as $name) { if (array_key_exists($name, $processedMigrations)) { $this->runDown((object) $processedMigrations[$name], $pretend); } } return count($migrations); }