Commit 0bcd5891 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(migrations): support Closure-based 'up'/'down' in MigrationRunner

The runner was calling splitStatements(string) directly on migration['up']
without checking whether it was a Closure, causing a fatal type error on
all idempotent closure-based migrations (Phase_94_001, _002, Phase_96_001).
Now checks is_callable() first and invokes the closure, falling back to
string SQL splitting for plain-string migrations.
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 8a66d739
......@@ -38,13 +38,17 @@ final class MigrationRunner
if (is_array($migration) && isset($migration['up'])) {
$upSql = $migration['up'];
$statements = $this->splitStatements($upSql);
if (is_callable($upSql)) {
$upSql($this->db);
} else {
$statements = $this->splitStatements((string) $upSql);
foreach ($statements as $stmt) {
$stmt = trim($stmt);
if ($stmt !== '') {
$this->db->raw($stmt);
}
}
}
} elseif (is_object($migration) && method_exists($migration, 'up')) {
$migration->up($this->db);
} elseif (is_callable($migration)) {
......@@ -93,13 +97,18 @@ final class MigrationRunner
$migration = require $file;
if (is_array($migration) && isset($migration['down'])) {
$statements = $this->splitStatements($migration['down']);
$downSql = $migration['down'];
if (is_callable($downSql)) {
$downSql($this->db);
} else {
$statements = $this->splitStatements((string) $downSql);
foreach ($statements as $stmt) {
$stmt = trim($stmt);
if ($stmt !== '') {
$this->db->raw($stmt);
}
}
}
} elseif (is_object($migration) && method_exists($migration, 'down')) {
$migration->down($this->db);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment