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:
@@ -141,9 +141,12 @@ foreach ($pending as $file) {
|
|||||||
// DDL.
|
// DDL.
|
||||||
try {
|
try {
|
||||||
// Split by semicolon but respect statements properly
|
// 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(
|
$statements = array_values(array_filter(
|
||||||
array_map('trim', explode(';', $sql)),
|
array_map('trim', explode(';', $sqlNoComments)),
|
||||||
function($stmt) {
|
function($stmt) {
|
||||||
// Remove comments and check if there's actual SQL
|
// Remove comments and check if there's actual SQL
|
||||||
$cleaned = preg_replace('/--.*$/m', '', $stmt);
|
$cleaned = preg_replace('/--.*$/m', '', $stmt);
|
||||||
|
|||||||
Reference in New Issue
Block a user