Skip to content

Commit 3cfb940

Browse files
committed
fix: "migration:rollback -b" does not work due to TypeError
1 parent d2e50af commit 3cfb940

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

system/Commands/Database/MigrateRollback.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\CLI\BaseCommand;
1717
use CodeIgniter\CLI\CLI;
18+
use CodeIgniter\Database\MigrationRunner;
1819
use Throwable;
1920

2021
/**
@@ -78,10 +79,23 @@ public function run(array $params)
7879
// @codeCoverageIgnoreEnd
7980
}
8081

82+
/** @var MigrationRunner $runner */
8183
$runner = service('migrations');
8284

8385
try {
8486
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
87+
88+
if (is_string($batch)) {
89+
if (! ctype_digit($batch)) {
90+
CLI::error('Invalid batch number: ' . $batch, 'light_gray', 'red');
91+
CLI::newLine();
92+
93+
return EXIT_ERROR;
94+
}
95+
96+
$batch = (int) $batch;
97+
}
98+
8599
CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');
86100

87101
if (! $runner->regress($batch)) {

0 commit comments

Comments
 (0)