Fix: normalize nullsNotDistinct to false in pgSerializer to stop spurious truncate prompts#5989
Open
tsushanth wants to merge 1 commit into
Open
Conversation
When a unique() constraint is defined without .nullsNotDistinct(), the ORM sets nullsNotDistinct to undefined. The DB introspector always returns false for this field. PgSquasher.squashUnique serializes the field as-is, producing different squashed strings for the same constraint: schema: ...;undefined db: ...;false The differ sees this as an altered constraint, which the push logic turns into a delete + re-add, triggering the truncate prompt on every push run. Normalizing undefined to false at serialization time aligns the two snapshot sources and stops the spurious re-add cycle. Fixes drizzle-team#5955
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.
Fixes #5955
Problem
drizzle:pushrepeatedly prompts to truncate a table for aunique()constraint that already exists in the database and hasn't changed.Root cause:
nullsNotDistinctmismatch between the two snapshot sources fed into the differ:pgSerializer.tsline 320): storesunq.nullsNotDistinctverbatim. A plainunique()without.nullsNotDistinct()leaves this field asundefined.pgSerializer.tsline 1357): always storesfalsefor existingUNIQUEconstraints.PgSquasher.squashUniqueserializes the field directly —undefinedandfalsestringify differently, so the differ sees the constraint as altered on every run. The diff engine turns an altered unique constraint into drop + re-add, which requires a truncate.Fix
One line in
drizzle-kit/src/serializer/pgSerializer.ts:This aligns the schema-side snapshot with what the DB introspector produces for the same constraint, so the differ sees no change.