fix(sqlite-kit): scaffold BOOLEAN columns as integer with boolean mode - #6186
fix(sqlite-kit): scaffold BOOLEAN columns as integer with boolean mode#6186webdevsamran wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ebbf6b7862
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| defaultFromIntrospect: (value) => { | ||
| const it = trimChar(value, "'"); | ||
| const lower = it.toLowerCase(); | ||
| if (lower === 'true' || lower === 'false') return lower; |
There was a problem hiding this comment.
Preserve quoted boolean defaults as SQL strings
When an existing schema declares BOOLEAN DEFAULT 'true' or BOOLEAN DEFAULT 'false', SQLite introspection returns a quoted string literal, but this normalization strips the quotes and converts it into a TypeScript boolean. The scaffolded schema therefore emits .default(true) or .default(false), recreating the default as integer 1/0 instead of the original text value and potentially changing query behavior; only unquoted SQL keywords should be normalized.
Useful? React with 👍 / 👎.
| if ( | ||
| ['boolean', 'bool'].some((it) => lowered.startsWith(it)) | ||
| ) { | ||
| return 'boolean'; |
There was a problem hiding this comment.
Preserve boolean mode when scaffolding view columns
When a pulled view exposes a column inherited from a BOOLEAN/BOOL table column, SQLite reports that declared type for the view and this new mapping routes it to Int. However, createViewColumns() discards the options returned by Int.toTs() and emits integer() rather than integer({ mode: 'boolean' }), so the generated view field is typed and decoded as a number instead of a boolean. The view generator must propagate the boolean-mode option before mapping these types to boolean.
Useful? React with 👍 / 👎.
Summary of Changes
Fixes #6182
Problem
When pulling/introspecting a SQLite database schema with
BOOLEANcolumns and default values (e.g.pending BOOLEAN NOT NULL DEFAULT true),drizzle-kitpreviously mappedBOOLEANundernumericAffinities, generatingnumeric().default(true).notNull().In Drizzle ORM,
numeric()does not accept boolean literals as defaults, resulting in TypeScript compilation errors:Argument of type 'boolean' is not assignable to parameter of type 'string | SQL<unknown>'.ts(2345)Additionally, uppercase SQL defaults like
DEFAULT TRUE/DEFAULT FALSEwere scaffolded verbatim as undeclared identifiers.Solution
booleanandboolfromnumericAffinitiestointAffinitiesand updatedsqlTypeFrom()to return'boolean'.Int.toTs()now checks if the column type is boolean and outputsoptions: { mode: 'boolean' }with normalized lowercase'true'/'false'defaults, generatinginteger({"mode":"boolean"}).default(true)(which maps toSQLiteBooleanBuilderin Drizzle ORM).Int.defaultFromIntrospect()normalizes case-insensitiveTRUE/FALSEstrings from SQLite catalog introspection into lowercase'true'/'false'.drizzle-kit/tests/sqlite/grammar.test.tsverifyingsqlTypeFrom,typeFor,toTs, andparseDefaultwith various boolean formats (BOOLEAN,bool,true,false,TRUE,FALSE,1,0,null).