-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate deferrable: true
option of add_foreign_key
#47659
Deprecate deferrable: true
option of add_foreign_key
#47659
Conversation
b0bc930
to
86a5756
Compare
I think it needs to deprecate
|
86a5756
to
7b6ecbf
Compare
7b6ecbf
to
ab07a79
Compare
deferrable
option of add_foreign_key
must now be false or symbolsdeferrable: true
option of add_foreign_key
b9be31a
to
2bbcbca
Compare
@yahonda Fixed 😄 🙏 |
4dae78e
to
44ed638
Compare
4105ded
to
1ce57d3
Compare
@yahonda Fixed 😄 👍 |
1ce57d3
to
1bc8325
Compare
Would you resolve the conflicts in the activerecord/CHANGELOG.md ? |
1bc8325
to
7341df3
Compare
@yahonda done 👍 |
7341df3
to
48d255b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed to deprecate :deferrable:true
as it can also take :deferred
and :immediate
, both of which are truth values. I think it is clearer to just allow :deferred
and :immediate
.
I'd like hear from other committers/core members to get some more opinion/approvals.
This PR looks great to me, could https://edgeguides.rubyonrails.org/active_record_postgresql.html#deferrable-foreign-keys get updated at the same time? |
48d255b
to
bf79e1b
Compare
I've rebased and fixed conflict. |
@ghiculescu The guide has also been modified in this PR 👍 Please check Files changed. |
@@ -1131,6 +1131,17 @@ def add_foreign_key(from_table, to_table, **options) | |||
return if options[:if_not_exists] == true && foreign_key_exists?(from_table, to_table, **options.slice(:column)) | |||
|
|||
options = foreign_key_options(from_table, to_table, options) | |||
|
|||
if options[:deferrable] == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have commented this in advance, I think this requirement is PostgreSQL adapter specific.
So how about creating add_foreign_key(from_table, to_table, **options)
method in activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb to run these warnings validations?
@@ -1724,6 +1735,12 @@ def check_constraint_for!(table_name, expression: nil, **options) | |||
raise(ArgumentError, "Table '#{table_name}' has no check constraint for #{expression || options}") | |||
end | |||
|
|||
def assert_valid_deferrable(deferrable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this method to activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
1002dd4
to
62b260d
Compare
@yahonda fixed 🤩 |
Let's resolve the conflict at activerecord/CHANGELOG.md . other than it looks good. |
`deferrable: true` is deprecated in favor of `deferrable: :immediate`, and will be removed in Rails 7.2. Because `deferrable: true` and `deferrable: :deferred` are hard to understand. Both true and :deferred are truthy values. This behavior is the same as the deferrable option of the add_unique_key method, added in rails#46192. *Hiroyuki Ishii*
62b260d
to
896d359
Compare
@yahonda rebased 👍 |
Motivation / Background
deferrable: true
is deprecated in favor ofdeferrable: :immediate
, and will be removed in Rails 7.2.Because
deferrable: true
anddeferrable: :deferred
are hard to understand.Both true and :deferred are truthy values.
This behavior is the same as the deferrable option of the add_unique_key method, added in #46192.
Detail
add_unique_key
method added in Add support for unique constraints (PostgreSQL-only). #46192,deferrable
now should be accept only symbols.deferrable: true
is deprecated now.ActiveRecord::Migration[7.0]
so thatdeferrable: true
is available without deprecation message in older migration files.Additional information
The SQL generated will be slightly different, but unaffected.
#46192 confirms that
DEFERRABLE
andDEFERRABLE INITIALLY IMMEDIATE
are equivalent.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]