Skip to content

Commit

Permalink
fix: "migration:rollback -b" does not work due to TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jun 12, 2024
1 parent d2e50af commit 3cfb940
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Database\MigrationRunner;
use Throwable;

/**
Expand Down Expand Up @@ -78,10 +79,23 @@ public function run(array $params)
// @codeCoverageIgnoreEnd
}

/** @var MigrationRunner $runner */
$runner = service('migrations');

try {
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;

if (is_string($batch)) {
if (! ctype_digit($batch)) {
CLI::error('Invalid batch number: ' . $batch, 'light_gray', 'red');
CLI::newLine();

return EXIT_ERROR;
}

$batch = (int) $batch;
}

CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

if (! $runner->regress($batch)) {
Expand Down

0 comments on commit 3cfb940

Please sign in to comment.