Skip to content

[Sqlite-kit] Scaffold BOOLEAN columns as integer(mode: 'boolean'), not numeric() - #6184

Open
Bryandero98 wants to merge 1 commit into
drizzle-team:mainfrom
Bryandero98:fix/sqlite-introspect-boolean-column
Open

[Sqlite-kit] Scaffold BOOLEAN columns as integer(mode: 'boolean'), not numeric()#6184
Bryandero98 wants to merge 1 commit into
drizzle-team:mainfrom
Bryandero98:fix/sqlite-introspect-boolean-column

Conversation

@Bryandero98

Copy link
Copy Markdown

What changed

Fixes #6182.

SQLite has no boolean storage class, so mapSqlToSqliteType (in drizzle-kit/src/serializer/sqliteSerializer.ts) had no case for it, and every BOOLEAN column fell through to the numeric() catch-all. A literal DEFAULT true/DEFAULT FALSE made this worse: PRAGMA table_info returns 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), and introspect-sqlite.ts spliced it unchanged into .default(...). That produced either a raw JS boolean literal typed against numeric()'s string | SQL<unknown> default (Argument of type 'boolean' is not assignable...), or a bare TRUE/FALSE identifier TypeScript can't resolve at all, since JS/TS boolean literals are lowercase.

BOOLEAN now maps to its own 'boolean' type and is scaffolded as integer(name, { mode: 'boolean' }) - sqlite-core's idiomatic representation, since there's no separate boolean() builder. Its default is normalized to a lowercase true/false literal, unwrapping the parenthesized form before comparing. Column-import collection maps the new 'boolean' type to 'integer' for its import, since sqlite-core has no boolean() 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-caps true/false default forms) plus unrelated numeric/integer/text columns in the same table, to guard against regressing what those already scaffold correctly.

I wasn't able to get a full pnpm install working in my environment (an unrelated, pre-existing drizzle-kit@0.25.0-b1faa33 self-referential devDependency pin 404s against the registry), so I verified the fix standalone: built a minimal environment with just better-sqlite3 + the runtime deps introspect-sqlite.ts/sqliteSerializer.ts actually 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 real vitest suite if a maintainer can confirm that pin is a known issue.

…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
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.

[BUG]: SQLite incorrectly scaffolds boolean column with drizzle-kit pull

1 participant