fix(drizzle-kit): handle hyphenated enum names in default value comparison#5592
Open
seojcarlos wants to merge 1 commit intodrizzle-team:betafrom
Open
fix(drizzle-kit): handle hyphenated enum names in default value comparison#5592seojcarlos wants to merge 1 commit intodrizzle-team:betafrom
seojcarlos wants to merge 1 commit intodrizzle-team:betafrom
Conversation
…rison The regex in trimDefaultValueSuffix did not match quoted enum names containing hyphens (e.g. "user-role"), causing drizzle-kit push to falsely detect schema changes on every run for columns with enum defaults. Added hyphen to the character class in the type-cast stripping regex so that values like 'customer'::"user-role" are correctly trimmed to 'customer'. Fixes drizzle-team#5569
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.
Summary
Fixes #5569
drizzle-kit pushfalsely detects schema changes for columns with enum defaults when the enum name contains hyphens (e.g."user-role"). This causes an infinite loop ofALTER TABLE ... SET DEFAULTstatements on every push.Root Cause
The regex in
trimDefaultValueSuffixstrips type-casting suffixes from PostgreSQL default values (e.g.'customer'::"user-role"→'customer'). However, the character class["\w.\s]does not include hyphens (-), so quoted enum names like"user-role"are not matched and the cast is not removed.This means the DB snapshot stores
'customer'::"user-role"while the schema serializer produces'customer', causing a diff on every push.Fix
Added
-to the character class in the regex:["\w.\s-]Before:
After:
Tests
Added 3 test cases to
drizzle-kit/tests/postgres/grammar.test.ts:'customer'::"user-role"→'customer''admin'::"my-custom-enum"→'admin''{a,b}'::"my-enum"[]→'{a,b}'All 42 existing tests continue to pass.
Changed Files
drizzle-kit/src/dialects/postgres/grammar.ts— 1 character fix in regexdrizzle-kit/tests/postgres/grammar.test.ts— 3 new test cases