Skip to content

Commit

Permalink
Added --graceful to migrateCommand (#6590)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Mar 13, 2024
1 parent 2788b80 commit 01c4220
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Commands/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Hyperf\Command\Concerns\Confirmable as ConfirmableTrait;
use Hyperf\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption;
use Throwable;

class MigrateCommand extends BaseCommand
{
Expand All @@ -34,9 +35,29 @@ public function __construct(protected Migrator $migrator)
public function handle()
{
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();

// Next, we will check to see if a path option has been defined. If it has
Expand Down Expand Up @@ -66,6 +87,7 @@ protected function getOptions(): array
['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'],
['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'],
];
}

Expand Down

0 comments on commit 01c4220

Please sign in to comment.