Skip to content

fix(drizzle-kit): handle hyphenated enum names in default value comparison#5592

Open
seojcarlos wants to merge 1 commit intodrizzle-team:betafrom
seojcarlos:fix/enum-default-hyphen-casting
Open

fix(drizzle-kit): handle hyphenated enum names in default value comparison#5592
seojcarlos wants to merge 1 commit intodrizzle-team:betafrom
seojcarlos:fix/enum-default-hyphen-casting

Conversation

@seojcarlos
Copy link
Copy Markdown

Summary

Fixes #5569

drizzle-kit push falsely detects schema changes for columns with enum defaults when the enum name contains hyphens (e.g. "user-role"). This causes an infinite loop of ALTER TABLE ... SET DEFAULT statements on every push.

Root Cause

The regex in trimDefaultValueSuffix strips 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:

'customer'::"user-role"  →  'customer'::"user-role"  (not stripped)

After:

'customer'::"user-role"  →  'customer'  (correctly stripped)

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 regex
  • drizzle-kit/tests/postgres/grammar.test.ts — 3 new test cases

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

1 participant