fix(db): strip inline -- comments before splitting schema statements
All checks were successful
PR Checks / server-tests (pull_request) Successful in 10m18s
PR Checks / client-build (pull_request) Successful in 9m32s
PR Checks / bot-install (pull_request) Successful in 9m26s

The schema loader stripped only full-line -- comments, then split the
file on ';'. A trailing comment containing a semicolon (e.g. the
mobile_auth_sessions.session_id column: `-- uuid; carried inside...`)
chopped the CREATE TABLE in half, so MariaDB got the fragment and failed
with `error ... near '' at line 3`, crash-looping the server on boot.

Strip -- comments on every line (full-line and trailing) before the ';'
split. Safe because the schema never places -- inside a string literal.

Verified by running ensureSchema() against a fresh MariaDB: all 49 tables
create cleanly and mobile_auth_sessions has all 11 columns.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-20 19:10:53 -05:00
parent dacc1bd4f7
commit d1b3351360

View File

@@ -51,11 +51,16 @@ async function ensureSchema({ retries = 10, delayMs = 2000 } = {}) {
const conn = await pool.getConnection()
try {
const sql = fs.readFileSync(SCHEMA_PATH, 'utf8')
// Strip full-line comments first, then split — so a leading comment block
// doesn't get glued onto (and discard) the statement that follows it.
// Strip `--` comments (full-line AND trailing) before splitting — so a
// leading comment block doesn't get glued onto the statement that follows
// it, and a `;` inside a trailing comment can't chop a statement in half.
// Safe because the schema never puts `--` inside a string literal.
const statements = sql
.split('\n')
.filter((line) => !line.trim().startsWith('--'))
.map((line) => {
const i = line.indexOf('--')
return i === -1 ? line : line.slice(0, i)
})
.join('\n')
.split(';')
.map((s) => s.trim())