From 13a0612f23323ab124ed7766f8a3b3b29167dfcc Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 3 Oct 2026 01:02:55 -0400 Subject: [PATCH] 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. --- migrations/migrate.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/migrations/migrate.php b/migrations/migrate.php index b34a8b4..b5a1c13 100644 --- a/migrations/migrate.php +++ b/migrations/migrate.php @@ -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);