Skip to content

fix(db): parse SQL schema files regardless of line endings (#241)#242

Merged
HugoFara merged 1 commit into
mainfrom
fix/sql-parser-crlf-line-endings
Jun 30, 2026
Merged

fix(db): parse SQL schema files regardless of line endings (#241)#242
HugoFara merged 1 commit into
mainfrom
fix/sql-parser-crlf-line-endings

Conversation

@HugoFara

@HugoFara HugoFara commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #241 — fresh installs fail to boot with Internal Server Error - A database error occurred. and MySQL error 1064 while applying db/schema/baseline.sql.

Root cause

SqlFileParser::parseFile() split statements on ';' . PHP_EOL. PHP_EOL is "\n" on the (Linux) server, so the split looks for the literal ";\n". When baseline.sql has CRLF line endings (e.g. cloned on Windows with core.autocrlf=true and built locally), the real boundary is ";\r\n" and never matches. The whole file then collapses into a single multi-statement string, which mysqli_query() rejects after the first statement with error 1064.

The issue's error context shows the tell-tale symptom: two CREATE TABLE statements (_migrations + users) concatenated into one query, every line ending in \r\n.

Fix

parseFile() now reads the file whole, normalizes CRLF/CRLF up front, then splits. Parsing is now independent of the file's origin OS, and CR-only files (which fgets() 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 real baseline.sql now parses into 18 individual statements (previously 1 blob), with zero multi-CREATE TABLE statements.

./vendor/bin/phpunit tests/backend/Core            # 1163 passed, 22 skipped
./vendor/bin/psalm --threads=1 SqlFileParser.php   # No errors
./vendor/bin/phpcs --standard=PSR12 ...            # clean

Notes

  • Likely warrants a 3.2.1 patch release since affected users can't self-heal a pre-built image.

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.
@HugoFara HugoFara merged commit 415ef1a into main Jun 30, 2026
14 checks passed
@HugoFara HugoFara deleted the fix/sql-parser-crlf-line-endings branch June 30, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to start LWT after installation

1 participant