Fix migration runner: strip -- comments before splitting statements

A semicolon inside a SQL comment (as in 001 and 003) cut statements in half and
made those migrations fail on a fresh database.
This commit is contained in:
2026-10-03 01:02:55 -04:00
parent 4885848375
commit 13a0612f23
+5 -2
View File
@@ -141,9 +141,12 @@ foreach ($pending as $file) {
// DDL.
try {
// Split by semicolon but respect statements properly
// Note: This doesn't handle semicolons in strings, but our migrations are simple
// Note: This doesn't handle semicolons in strings, but our migrations are simple.
// Full-line "--" comments are stripped first so a ";" inside a comment
// can't cut a statement in half.
$sqlNoComments = preg_replace('/^\s*--.*$/m', '', $sql);
$statements = array_values(array_filter(
array_map('trim', explode(';', $sql)),
array_map('trim', explode(';', $sqlNoComments)),
function($stmt) {
// Remove comments and check if there's actual SQL
$cleaned = preg_replace('/--.*$/m', '', $stmt);