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

View File

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