/** * Runs the database migrations for the extension. * * @param Extension $extension * @param bool|true $up */ public function migrate(Extension $extension, $up = true) { if ($extension->hasMigrations()) { $migrationDir = $extension->getPath() . '/migrations'; $this->app->bind('Illuminate\\Database\\Schema\\Builder', function ($container) { return $container->make('Illuminate\\Database\\ConnectionInterface')->getSchemaBuilder(); }); if ($up) { $this->migrator->run($migrationDir, $extension); } else { $this->migrator->reset($migrationDir, $extension); } } }
/** * Run "down" a migration instance. * * @param $path * @param string $file * @param string $path * @param Extension $extension * @return void */ protected function runDown($path, $file, Extension $extension = null) { $migration = $this->resolve($path, $file); $this->runClosureMigration($migration, 'down'); // Once we have successfully run the migration "down" we will remove it from // the migration repository so it will be considered to have not been run // by the application then will be able to fire by any later operation. $this->repository->delete($file, $extension ? $extension->getId() : null); $this->note("<info>Rolled back:</info> {$file}"); }
/** * Runs the database migrations to reset the database to its old state. * * @param Extension $extension */ public function migrateDown(Extension $extension) { $this->migrate($extension->getId(), false); }
/** * Rolls all of the currently applied migrations back. * * @param string $path * @param Extension $extension * @return int */ public function reset($path, Extension $extension = null) { $this->notes = []; $migrations = array_reverse($this->repository->getRan($extension->getId())); $this->requireFiles($path, $migrations); $count = count($migrations); if ($count === 0) { $this->note('<info>Nothing to rollback.</info>'); } else { foreach ($migrations as $migration) { $this->runDown($migration, $extension); } } return $count; }