fix(import): keep a column declared NULL nullable - #1124
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
Conversation
node-sql-parser emits a node for BOTH nullability markers:
a INT NULL -> nullable = { type: "null", value: "null" }
b INT NOT NULL -> nullable = { type: "not null", value: "not null" }
c INT -> nullable = undefined
The importers tested that node for truthiness, so an explicitly
nullable column was imported as NOT NULL. Only the omitted marker was
read correctly.
Check the marker's type instead. Affects mysql, mariadb, postgres,
mssql and sqlite; oraclesql already reads the value rather than the
node's truthiness and is unchanged.
|
@NgoQuocViet2001 is attempting to deploy a commit to the dottle's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
The bug
Importing SQL that declares a column explicitly nullable turns it into
NOT NULL.ais declaredNULL, but it arrives in the diagram with the Not null box ticked. The column's nullability is silently inverted, and re-exporting the diagram then emitsa INT NOT NULL— so a round-trip through drawDB changes the schema.Why
node-sql-parseremits a node for both markers, not just forNOT NULL:The importers tested that node for truthiness:
Both markers are truthy objects, so
NULLandNOT NULLwere treated identically. Only the omitted marker was read correctly, which is why the bug is invisible on the commonCREATE TABLE t (c INT)shape.The fix reads the marker's type instead.
Verified
Ran the real importers through the public
importSQL()entry point — the same oneEditorHeader/Modal/Modal.jsxcalls — withnode-sql-parserat the versionpackage-lock.jsonpins:b(NOT NULL) andc(omitted) are unchanged, which is the part that matters — this only stops the explicitNULLmarker from being misread.Scope
Five importers share the same line:
mysql,mariadb,mssql,postgres,sqlite.oraclesqlis not affected and is left alone — it already inspects the value (c.constraint.not_null === "not null") rather than the node's truthiness, so it was reading the marker correctly all along.Checks
npm run lint— clean (--max-warnings 0).npm run build— succeeds.Both are what
.github/workflows/build.ymlruns. The repo has no test suite, so there is nowhere to hang a regression test; the reproduction above is a scratch script run against the real modules and is not part of the diff. Happy to add a small test setup separately if you would like one — it seemed wrong to bundle that into a bug fix.