[SQLite-kit] Wrap expression defaults in parentheses#5652
Open
aayushbaluni wants to merge 1 commit intodrizzle-team:mainfrom
Open
[SQLite-kit] Wrap expression defaults in parentheses#5652aayushbaluni wants to merge 1 commit intodrizzle-team:mainfrom
aayushbaluni wants to merge 1 commit intodrizzle-team:mainfrom
Conversation
SQLite requires expression defaults (e.g. datetime('now')) to be
enclosed in parentheses. Without this, drizzle-kit push generates
invalid SQL like DEFAULT datetime('now') instead of
DEFAULT (datetime('now')), causing SQLITE_ERROR syntax errors during
table recreation.
Fixes drizzle-team#5634
Made-with: Cursor
5f26da1 to
2807309
Compare
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's Changed
Fixes #5634
When
drizzle-kit pushrecreates a SQLite table (e.g. to add a named UNIQUE constraint), expression defaults likedatetime('now')are emitted without the parentheses SQLite requires:Root Cause
SQLiteCreateTableConvertorandSQLiteAlterTableAddColumnConvertorinsqlgenerator.tsinterpolatecolumn.defaultdirectly into the SQL without wrapping expression defaults. SQLite's grammar requires non-literal defaults (function calls, expressions) to be enclosed in parentheses.Fix
Added
wrapSqliteExprDefault()— a small helper that detects whether a default value is a simple literal (string, number,NULL,CURRENT_TIMESTAMP, etc.) or an expression, and wraps expressions in parentheses. Applied to bothSQLiteCreateTableConvertor.convert()andSQLiteAlterTableAddColumnConvertor.convert().Literal defaults (strings, numbers, booleans,
CURRENT_TIMESTAMP) pass through unchanged — no double-wrapping.Tests Added
Three new test cases in
sqlite-columns.test.ts:All existing SQLite tests (columns, tables, generated, checks, libsql) continue to pass.
Made with Cursor