Added --graceful to migrateCommand (#6590)

This commit is contained in:
Deeka Wong 2024-03-13 17:57:10 +08:00 committed by GitHub
parent 813dda3c6c
commit 0e7435db45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -5,6 +5,7 @@
- [#6576](https://github.com/hyperf/hyperf/pull/6576) Added `Hyperf\Stringable\Str::apa()` method. - [#6576](https://github.com/hyperf/hyperf/pull/6576) Added `Hyperf\Stringable\Str::apa()` method.
- [#6577](https://github.com/hyperf/hyperf/pull/6577) Support setup command traits before running. - [#6577](https://github.com/hyperf/hyperf/pull/6577) Support setup command traits before running.
- [#6579](https://github.com/hyperf/hyperf/pull/6579) Added `now()` and `today()` helper functions. - [#6579](https://github.com/hyperf/hyperf/pull/6579) Added `now()` and `today()` helper functions.
- [#6590](https://github.com/hyperf/hyperf/pull/6590) Added `--graceful` to migrateCommand.
# v3.1.12 - 2024-03-07 # v3.1.12 - 2024-03-07

View File

@ -14,6 +14,7 @@ namespace Hyperf\Database\Commands\Migrations;
use Hyperf\Command\Concerns\Confirmable as ConfirmableTrait; use Hyperf\Command\Concerns\Confirmable as ConfirmableTrait;
use Hyperf\Database\Migrations\Migrator; use Hyperf\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Throwable;
class MigrateCommand extends BaseCommand class MigrateCommand extends BaseCommand
{ {
@ -34,9 +35,29 @@ class MigrateCommand extends BaseCommand
public function handle() public function handle()
{ {
if (! $this->confirmToProceed()) { if (! $this->confirmToProceed()) {
return; return 0;
} }
try {
$this->runMigrations();
} catch (Throwable $e) {
if ($this->input->getOption('graceful')) {
$this->output->warning($e->getMessage());
return 0;
}
throw $e;
}
return 0;
}
/**
* Run the pending migrations.
*/
protected function runMigrations()
{
$this->prepareDatabase(); $this->prepareDatabase();
// Next, we will check to see if a path option has been defined. If it has // Next, we will check to see if a path option has been defined. If it has
@ -66,6 +87,7 @@ class MigrateCommand extends BaseCommand
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'], ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'],
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run'], ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run'],
['step', null, InputOption::VALUE_NONE, 'Force the migrations to be run so they can be rolled back individually'], ['step', null, InputOption::VALUE_NONE, 'Force the migrations to be run so they can be rolled back individually'],
['graceful', null, InputOption::VALUE_NONE, 'Return a successful exit code even if an error occurs'],
]; ];
} }