Skip to content

Conversation

@kevinansfield
Copy link
Member

Summary

This PR fixes SQL syntax issues that prevent knex-migrator from working with better-sqlite3, which enforces stricter SQL standards than the original sqlite3 package.

The Issue:

  • In SQL, double quotes (") are for identifiers (column/table names) - Single quotes (') are for string literals
  • The query SELECT name FROM sqlite_master WHERE type="table" incorrectly uses double quotes for the string literal "table"
  • better-sqlite3 enforces this distinction and rejects the query

The Fix:

  • Changed type="table" to type='table' in lib/database.js:183
  • Updated all test migration files to use proper SQL string literal syntax

Related:

@kevinansfield kevinansfield force-pushed the claude/fix-knex-migrator-blocker-01QyHSqNTPPXHVNUgB1Fq4Gu branch from 68db4c7 to b6f5aa4 Compare December 2, 2025 17:41
@kevinansfield kevinansfield changed the title Used single quotes for SQL string literals for better-sqlite3 compatibility Used single quotes for SQL string literals for better compatibility Dec 2, 2025
- Add better-sqlite3 v12.5.0 as a dev dependency
- Create test config for better-sqlite3 environment
- Add better-sqlite3 to the CI testing matrix alongside sqlite3 and mysql8
better-sqlite3 requires Node 20.x or later, so exclude it from
the Node 18.12.1 test matrix.
This allows yarn install to succeed on Node 18 where better-sqlite3
is not supported, similar to how sqlite3 is handled.
@kevinansfield kevinansfield changed the base branch from main to claude/add-better-sqlite3-ci-01QYHBgA4t2aaECXK3Nb6Smu December 2, 2025 17:57
@kevinansfield kevinansfield changed the base branch from claude/add-better-sqlite3-ci-01QYHBgA4t2aaECXK3Nb6Smu to main December 2, 2025 17:59
…ility

The `better-sqlite3` package enforces stricter SQL standards than the
original `sqlite3` package. In SQL, double quotes are for identifiers
while single quotes are for string literals.

This change fixes the sqlite_master query in lib/database.js and updates
all test migration files to use proper SQL string literal syntax. Uses
template literals to satisfy ESLint single-quote rule while allowing
single quotes in SQL.

This unblocks the Ghost migration from sqlite3 to better-sqlite3 (see
TryGhost/Ghost#25556).
@kevinansfield kevinansfield force-pushed the claude/fix-knex-migrator-blocker-01QyHSqNTPPXHVNUgB1Fq4Gu branch from b6f5aa4 to 3ee0c93 Compare December 2, 2025 18:01
Changes:
1. Use template literals in generateMigrationScript to allow single quotes
   in SQL strings without escaping issues
2. Fix SQL string literals in test files to use single quotes
3. Add better-sqlite3 error code check (SQLITE_ERROR) alongside sqlite3
   errno checks in lib/index.js for isDatabaseOK
4. Update implicit_commits_spec.js to handle better-sqlite3 error format

All 95 tests now pass with both sqlite3 and better-sqlite3.
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.

3 participants