Skip to content

Show DEFERRABLE INITIALLY on foreign keys - #365

Merged
OdenTakashi merged 2 commits into
drwl:mainfrom
kamipo:support-deferrable-constraints
Jul 23, 2026
Merged

Show DEFERRABLE INITIALLY on foreign keys#365
OdenTakashi merged 2 commits into
drwl:mainfrom
kamipo:support-deferrable-constraints

Conversation

@kamipo

@kamipo kamipo commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Emit DEFERRABLE INITIALLY IMMEDIATE|DEFERRED on foreign key annotations, alongside the existing ON DELETE / ON UPDATE metadata. Related to #364.

Motivation

Rails exposes deferrable foreign keys via ForeignKeyDefinition#deferrable, but annotaterb was silently dropping the flag — a foreign key created with add_foreign_key ..., deferrable: :deferred was indistinguishable from a plain one in the annotation.

Compatibility

Rails 7.0's extract_foreign_key_deferrable returns true for the initially-immediate case (7.1+ normalized this to :immediate); mapped trueIMMEDIATE for stable output. Guarded with respond_to?(:deferrable) for older Rails / other adapters.

kamipo and others added 2 commits July 19, 2026 21:09
PostgreSQL supports deferrable constraints on foreign keys. Rails'
ForeignKeyDefinition exposes this via #deferrable, but annotaterb was
ignoring it. Emit `DEFERRABLE INITIALLY IMMEDIATE|DEFERRED` alongside
the existing ON DELETE / ON UPDATE metadata.

Rails 7.0's extract_foreign_key_deferrable returns `true` for the
initially-immediate case (7.1+ normalized this to `:immediate`), so map
`true` back to IMMEDIATE to avoid emitting "INITIALLY TRUE".

@OdenTakashi OdenTakashi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. Looks great to me.

@OdenTakashi
OdenTakashi merged commit 615383a into drwl:main Jul 23, 2026
32 checks passed
@kamipo
kamipo deleted the support-deferrable-constraints branch July 23, 2026 09:33
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.

3 participants