Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Adds --graceful to php artisan migrate #50486

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading