fix(db): strip inline -- comments before splitting schema statements #82

Merged
whitlocktech merged 1 commits from fix/schema-loader-inline-comment-split into main 2026-07-21 00:31:15 +00:00
Member

Problem

The server crash-loops on boot against a fresh/live database, failing to ensure the schema:

ERROR [server] failed to start server
(conn:5, no: 1064, SQLState: 42000) You have an error in your SQL syntax ... near '' at line 3
sql: CREATE TABLE IF NOT EXISTS mobile_auth_sessions (
  id             INT AUTO_INCREMENT PRIMARY KEY,
  session_id     CHAR(36)     NOT NULL UNIQUE,        -- uuid

Root cause

ensureSchema() in server/src/utils/db.js stripped only full-line -- comments, then split the schema file on ;. The mobile_auth_sessions.session_id column carries a trailing comment that contains a semicolon:

session_id  CHAR(36)  NOT NULL UNIQUE,  -- uuid; carried inside the signed sso_tx (mode 'mobile')

That embedded ; split the CREATE TABLE in half, so MariaDB received the truncated fragment (ending at -- uuid) and rejected it — exactly the near '' at line 3 error above. Not DB-version-specific; the bug had simply never been triggered until a column comment happened to contain a ;.

Fix

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

Verification

  • Ran the actual ensureSchema() against a fresh MariaDB: schema ensured, 49 tables created, mobile_auth_sessions has all 11 columns.
  • Full server test suite: 284 pass, 0 fail.

No docs/protocol/API/schema change — this is loader behavior only.


AI-assisted: authored with Claude Code (see commit Co-Authored-By trailer).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NgyHnrNa8WwG3doxvxjuCr

## Problem The server crash-loops on boot against a fresh/live database, failing to ensure the schema: ``` ERROR [server] failed to start server (conn:5, no: 1064, SQLState: 42000) You have an error in your SQL syntax ... near '' at line 3 sql: CREATE TABLE IF NOT EXISTS mobile_auth_sessions ( id INT AUTO_INCREMENT PRIMARY KEY, session_id CHAR(36) NOT NULL UNIQUE, -- uuid ``` ## Root cause `ensureSchema()` in `server/src/utils/db.js` stripped only **full-line** `--` comments, then split the schema file on `;`. The `mobile_auth_sessions.session_id` column carries a **trailing** comment that contains a semicolon: ```sql session_id CHAR(36) NOT NULL UNIQUE, -- uuid; carried inside the signed sso_tx (mode 'mobile') ``` That embedded `;` split the `CREATE TABLE` in half, so MariaDB received the truncated fragment (ending at `-- uuid`) and rejected it — exactly the `near '' at line 3` error above. Not DB-version-specific; the bug had simply never been triggered until a column comment happened to contain a `;`. ## Fix Strip `--` comments on **every** line (full-line and trailing) before the `;` split. Safe because the schema never places `--` inside a string literal (verified with a grep over `schema.sql`). ## Verification - Ran the actual `ensureSchema()` against a fresh MariaDB: schema ensured, **49 tables** created, `mobile_auth_sessions` has all **11 columns**. - Full server test suite: **284 pass, 0 fail**. No docs/protocol/API/schema change — this is loader behavior only. --- AI-assisted: authored with Claude Code (see commit `Co-Authored-By` trailer). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01NgyHnrNa8WwG3doxvxjuCr
wtclaude added 1 commit 2026-07-21 00:11:22 +00:00
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
d1b3351360
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>
whitlocktech approved these changes 2026-07-21 00:11:57 +00:00
whitlocktech scheduled this pull request to auto merge when all checks succeed 2026-07-21 00:12:01 +00:00
whitlocktech merged commit 86420661b5 into main 2026-07-21 00:31:15 +00:00
whitlocktech deleted branch fix/schema-loader-inline-comment-split 2026-07-21 00:31:15 +00:00
Sign in to join this conversation.
No description provided.