diff --git a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php index 5f7e1c87b10f..12cab1eb1032 100755 --- a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php @@ -31,7 +31,8 @@ class MigrateCommand extends BaseCommand implements Isolatable {--pretend : Dump the SQL queries that would be run} {--seed : Indicates if the seed task should be re-run} {--seeder= : The class name of the root seeder} - {--step : Force the migrations to be run so they can be rolled back individually}'; + {--step : Force the migrations to be run so they can be rolled back individually} + {--graceful : Return a successful exit code even if an error occurs}'; /** * The console command description. @@ -80,6 +81,28 @@ public function handle() return 1; } + try { + $this->runMigrations(); + } catch (Throwable $e) { + if ($this->option('graceful')) { + $this->components->warn($e->getMessage()); + + return 0; + } + + throw $e; + } + + return 0; + } + + /** + * Run the pending migrations. + * + * @return void + */ + protected function runMigrations() + { $this->migrator->usingConnection($this->option('database'), function () { $this->prepareDatabase(); @@ -102,8 +125,6 @@ public function handle() ]); } }); - - return 0; } /**