Skip to content

Commit

Permalink
[11.x] Adds --graceful to php artisan migrate (#50486)
Browse files Browse the repository at this point in the history
* Adds `--graceful`

* Update MigrateCommand.php

* Update MigrateCommand.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
nunomaduro and taylorotwell authored Mar 12, 2024
1 parent 64a9ac2 commit 5701008
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Illuminate/Database/Console/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand All @@ -102,8 +125,6 @@ public function handle()
]);
}
});

return 0;
}

/**
Expand Down

0 comments on commit 5701008

Please sign in to comment.