Repository navigation
fix(export): emit the comma before inline foreign keys on SQLite - #1114
Merged
1ilit merged 1 commit intoAug 23, 2026
Merged
Conversation
A SQLite table with a foreign key but no primary key exported as invalid
SQL. The separator before the inline FOREIGN KEY block was nested inside
the primary-key branch, so it was only emitted when the table happened to
have a primary key:
CREATE TABLE IF NOT EXISTS "post" (
"author_id" INTEGER FOREIGN KEY ("author_id") REFERENCES "author"("id")
sqlite3 rejects that with `near "FOREIGN": syntax error`. Foreign keys on
a table without a primary key are ordinary — a join table, or any child
row keyed by something other than a declared PK.
Moving the separator out of the primary-key branch and keying it on the
foreign-key block itself fixes both SQLite export paths: `toSqlite` and
`jsonToSQLite`. Output for tables that do have a primary key is byte for
byte unchanged.
|
@ntdatt812 is attempting to deploy a commit to the dottle's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defect
A SQLite table that has a foreign key but no primary key exports as invalid SQL.
Repro —
post.author_idreferencesauthor.id, andposthas no primary key:sqlite3rejects it:Cause
The separator that precedes the inline
FOREIGN KEYblock is nested inside the primary-key branch:So the
,\nis only emitted when the table happens to have a primary key. With a primary key the output is correct, which is why this isn't more visible — but a foreign key on a table without a declared primary key is ordinary: a join table, or any child row keyed by something other than a PK.Fix
Move the separator out of the primary-key branch and key it on the foreign-key block itself:
Both SQLite export paths had the same construct, so both are fixed:
src/utils/exportSQL/sqlite.js—toSqlitesrc/utils/exportSQL/generic.js—jsonToSQLiteOther dialects are unaffected: MySQL, MariaDB, Postgres, MSSQL and Oracle emit foreign keys as separate
ALTER TABLEstatements rather than inline.Verification
There's no test harness in the repo, so I drove the real export functions directly and fed the output to an actual SQLite engine (
bun:sqlite):near "FOREIGN": syntax errorVerified on both
toSqliteandjsonToSQLite. Output for tables that do have a primary key is unchanged.npx eslintclean on both changed files.