fix(db): parse SQL schema files regardless of line endings (#241)#242
Merged
Conversation
SqlFileParser::parseFile split statements on `';' . PHP_EOL`, which is `";\n"` on a Linux host. A schema file with CRLF (or CR) line endings — e.g. committed from Windows or baked into an image — never matches that boundary, so the entire baseline.sql collapses into one multi-statement string. mysqli_query() runs only the first statement and rejects the rest with error 1064, surfacing as "Internal Server Error - A database error occurred." on first boot (issue #241). Read the file whole, normalize CRLF/CR to LF up front, then split. This makes parsing independent of the file's origin OS and also fixes CR-only files, which fgets() could not line-split at all. Add a data-provider regression test covering LF, CRLF, and CR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #241 — fresh installs fail to boot with
Internal Server Error - A database error occurred.and MySQL error 1064 while applyingdb/schema/baseline.sql.Root cause
SqlFileParser::parseFile()split statements on';' . PHP_EOL.PHP_EOLis"\n"on the (Linux) server, so the split looks for the literal";\n". Whenbaseline.sqlhas CRLF line endings (e.g. cloned on Windows withcore.autocrlf=trueand built locally), the real boundary is";\r\n"and never matches. The whole file then collapses into a single multi-statement string, whichmysqli_query()rejects after the first statement with error 1064.The issue's error context shows the tell-tale symptom: two
CREATE TABLEstatements (_migrations+users) concatenated into one query, every line ending in\r\n.Fix
parseFile()now reads the file whole, normalizesCRLF/CR→LFup front, then splits. Parsing is now independent of the file's origin OS, and CR-only files (whichfgets()could not line-split at all) also work.Tests
Added a data-provider regression test (
testParseFileSplitsStatementsForAnyLineEnding) covering LF, CRLF, and CR. Verified end-to-end that a CRLF copy of the realbaseline.sqlnow parses into 18 individual statements (previously 1 blob), with zero multi-CREATE TABLEstatements.Notes