Skip to content

fix: support DEFERRABLE attribute on unique constraints#274

Open
joaquinhuigomez wants to merge 1 commit intostripe:mainfrom
joaquinhuigomez:fix/deferrable-unique-constraint
Open

fix: support DEFERRABLE attribute on unique constraints#274
joaquinhuigomez wants to merge 1 commit intostripe:mainfrom
joaquinhuigomez:fix/deferrable-unique-constraint

Conversation

@joaquinhuigomez
Copy link
Copy Markdown

Read condeferrable and condeferred from pg_constraint during schema introspection. Include deferrable state in constraint comparison and DDL generation.

Previously, deferrable unique constraints always produced a spurious diff because the tool didn't track the deferrable attribute. When recreating the constraint via ADD CONSTRAINT ... UNIQUE USING INDEX, the DEFERRABLE / INITIALLY DEFERRED clause was omitted, so the regenerated schema never matched the original.

Changes:

  • queries.sql / queries.sql.go: fetch condeferrable and condeferred from pg_constraint in the GetIndexes query
  • schema.go: add IsDeferrable and IsInitiallyDeferred fields to IndexConstraint
  • sql_generator.go: append DEFERRABLE INITIALLY DEFERRED or DEFERRABLE INITIALLY IMMEDIATE to the ADD CONSTRAINT ... USING INDEX DDL when applicable
  • index_cases_test.go: acceptance tests for adding, no-op, and changing deferrable unique constraints

Closes #273

Read condeferrable and condeferred from pg_constraint during schema
introspection. Include deferrable state in constraint comparison
and DDL generation to prevent spurious diffs.

Closes stripe#273
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 28, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 28, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

[BUG] Deferrable unique constraint produces error and spurious diff in plan

1 participant