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,11 +38,15 @@ final class MigrationRunner ...@@ -38,11 +38,15 @@ final class MigrationRunner
if (is_array($migration) && isset($migration['up'])) { if (is_array($migration) && isset($migration['up'])) {
$upSql = $migration['up']; $upSql = $migration['up'];
$statements = $this->splitStatements($upSql); if (is_callable($upSql)) {
foreach ($statements as $stmt) { $upSql($this->db);
$stmt = trim($stmt); } else {
if ($stmt !== '') { $statements = $this->splitStatements((string) $upSql);
$this->db->raw($stmt); foreach ($statements as $stmt) {
$stmt = trim($stmt);
if ($stmt !== '') {
$this->db->raw($stmt);
}
} }
} }
} elseif (is_object($migration) && method_exists($migration, 'up')) { } elseif (is_object($migration) && method_exists($migration, 'up')) {
...@@ -93,11 +97,16 @@ final class MigrationRunner ...@@ -93,11 +97,16 @@ final class MigrationRunner
$migration = require $file; $migration = require $file;
if (is_array($migration) && isset($migration['down'])) { if (is_array($migration) && isset($migration['down'])) {
$statements = $this->splitStatements($migration['down']); $downSql = $migration['down'];
foreach ($statements as $stmt) { if (is_callable($downSql)) {
$stmt = trim($stmt); $downSql($this->db);
if ($stmt !== '') { } else {
$this->db->raw($stmt); $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')) { } elseif (is_object($migration) && method_exists($migration, 'down')) {
......
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