[Sqlite-kit] Scaffold BOOLEAN columns as integer(mode: 'boolean'), not numeric() - #6184
Open
Bryandero98 wants to merge 1 commit into
Open
[Sqlite-kit] Scaffold BOOLEAN columns as integer(mode: 'boolean'), not numeric()#6184Bryandero98 wants to merge 1 commit into
Bryandero98 wants to merge 1 commit into
Conversation
…ric()
SQLite has no boolean storage class, so mapSqlToSqliteType had no case
for it and every BOOLEAN column fell through to the numeric() catch-all.
A literal `DEFAULT true`/`DEFAULT FALSE` on such a column made things
worse: PRAGMA table_info returns that default as the bare keyword text
("true", or "(FALSE)" - SQLite parenthesizes the all-caps form), which
was spliced unchanged into `.default(...)`. That produced either a raw
JS boolean literal typed against numeric()'s `string | SQL<unknown>`
default, or a bare TRUE/FALSE identifier that TypeScript can't resolve
at all, since JS/TS boolean literals are lowercase.
BOOLEAN now maps to its own type and is scaffolded as
integer(name, { mode: 'boolean' }), sqlite-core's idiomatic
representation (there is no separate boolean() builder). Its default is
normalized to a lowercase true/false literal, unwrapping the
parenthesized form PRAGMA table_info returns for the all-caps keyword
before comparing. Column-import collection now maps the new 'boolean'
type to 'integer' for its import, since sqlite-core has no boolean()
export.
Added a test reproducing the exact reported DDL (lowercase and
all-caps true/false defaults) plus unrelated numeric/integer/text
columns, to guard against regressing what those already scaffold
correctly.
Fixes drizzle-team#6182
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.
What changed
Fixes #6182.
SQLite has no boolean storage class, so
mapSqlToSqliteType(indrizzle-kit/src/serializer/sqliteSerializer.ts) had no case for it, and everyBOOLEANcolumn fell through to thenumeric()catch-all. A literalDEFAULT true/DEFAULT FALSEmade this worse:PRAGMA table_inforeturns that default as the bare keyword text ("true", or"(FALSE)"- SQLite parenthesizes the all-caps form, which I only found by actually running it, not by reading the report), andintrospect-sqlite.tsspliced it unchanged into.default(...). That produced either a raw JS boolean literal typed againstnumeric()'sstring | SQL<unknown>default (Argument of type 'boolean' is not assignable...), or a bareTRUE/FALSEidentifier TypeScript can't resolve at all, since JS/TS boolean literals are lowercase.BOOLEANnow maps to its own'boolean'type and is scaffolded asinteger(name, { mode: 'boolean' })- sqlite-core's idiomatic representation, since there's no separateboolean()builder. Its default is normalized to a lowercasetrue/falseliteral, unwrapping the parenthesized form before comparing. Column-import collection maps the new'boolean'type to'integer'for its import, sincesqlite-corehas noboolean()export.Testing
Added
tests/introspect/sqlite.test.ts->introspect boolean column with a literal true/false default, reproducing the exact reported DDL (both the lowercase and all-capstrue/falsedefault forms) plus unrelatednumeric/integer/textcolumns in the same table, to guard against regressing what those already scaffold correctly.I wasn't able to get a full
pnpm installworking in my environment (an unrelated, pre-existingdrizzle-kit@0.25.0-b1faa33self-referential devDependency pin 404s against the registry), so I verified the fix standalone: built a minimal environment with justbetter-sqlite3+ the runtime depsintrospect-sqlite.ts/sqliteSerializer.tsactually import, ran the exact scenario from the issue plus the additional cases now in the test file, and confirmed the generated output end-to-end. Happy to re-verify against the realvitestsuite if a maintainer can confirm that pin is a known issue.