From d1b3351360c0c516b9a2765a72e0ce6d5f4e59ff Mon Sep 17 00:00:00 2001 From: wtclaude Date: Mon, 20 Jul 2026 19:10:53 -0500 Subject: [PATCH] fix(db): strip inline -- comments before splitting schema statements 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 --- server/src/utils/db.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/utils/db.js b/server/src/utils/db.js index 368d4e5..362d41d 100644 --- a/server/src/utils/db.js +++ b/server/src/utils/db.js @@ -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())