-
Notifications
You must be signed in to change notification settings - Fork 22k
Use SET CONSTRAINTS
for disable_referential_integrity
without superuser privileges (take 2)
#27636
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
Use SET CONSTRAINTS
for disable_referential_integrity
without superuser privileges (take 2)
#27636
Conversation
r? @chancancode (@rails-bot has picked a reviewer for you, use r? to override) |
Let me add some comment for this pull request. There was a pull request #21233 which had merged and reverted back due to regressions. I believe this pull request addresses regression by loading necessary |
656edb7
to
8aba178
Compare
Sorry, test is failing after rebase 😢 |
8aba178
to
1829d0d
Compare
https://travis-ci.org/rails/rails/jobs/210515444
I found the cause. |
7f9d22d
to
f4ada34
Compare
It looks like the tests are passing and this pull request is ready for another review? I'm hopeful this will get merged for 5.1 as it is needed for Heroku CI to work. <3 Edit: Annnd RC1 just landed. :( |
@rafaelfranca @chancancode Could you review this pr? |
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.
Sorry for the delay. I just reviewed it. Could you made the change and rebase?
@@ -314,6 +314,12 @@ def supports_pgcrypto_uuid? | |||
postgresql_version >= 90400 | |||
end | |||
|
|||
# PostgreSQL 9.4 introduces ALTER TABLE ... ALTER CONSTRAINT but it has a bug and fixed in 9.4.2 | |||
# https://www.postgresql.org/docs/9.4/static/release-9-4-2.html |
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.
Could you move this comment to inside the method? Otherwise it will show as documentation of it.
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.
Moved and force pushed!
BTW, I followed the same way as supports_ranges?
so it may not be intended.
I created another PR #28543.
Please close the PR if the comment is intended 😅
f4ada34
to
b410c79
Compare
Because this comment is not document for `supports_ranges?` ref: rails#27636 (comment)
https://travis-ci.org/rails/rails/builds/214205098 ap, ac test is failed. I'll rebase and force push to restart test. |
…eruser privileges (take 2) Re-create rails#21233 eeac615 was reverted (127509c) because it breaks tests. ---------------- ref: 72c1557 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
b410c79
to
ef6391d
Compare
@rafaelfranca I moved the comment and force pushed 😃 |
@rafaelfranca Forgive my ignorance here, but are changes to master now targeting 5.1.1? Instead of 5.1.0? |
5.2.0 actually. But I'll backport it to 5.1.0 |
…ithout-superuser-privilege-take-2 Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges (take 2)
Backported in 1ccd40e |
That's great news! Thank you kindly. |
Reverted again in 2812694. Seems like referential actions other than the NO ACTION check cannot be deferred, even if the constraint is declared deferrable. |
…egrity-without-superuser-privilege-take-2" This reverts commit c1faca6, reversing changes made to 8c658a0. See #27636 (comment)
`:authors` has a foreign key to `:author_addresses`. If only `:authors` fixture loaded into the database which supports foreign key and checks the existing data when enabling foreien keys like Oracle, it raises the following error `ORA-02298: cannot validate (ARUNIT.FK_RAILS_94423A17A3) - parent keys not found` It is because there is no parent data exists in `author_addresses` table. Here are how other database with foreign key support works: - MySQL does not check the existing data when enabling foreign key by `foreign_key_checks=1` https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_foreign_key_checks > Setting foreign_key_checks to 1 does not trigger a scan of the existing table data. Therefore, rows added to the table while foreign_key_checks=0 will not be verified for consistency. - PostgreSQL database itself has a feature to check existing data when enabling foreign key and discussed at rails#27636, which is reverted.
If I understand this issue and fix correctly, you added a parameter so you can run tests with foreign keys, that normally require superuser privileges, without those privileges. If this is correct, (and I hope it is because I'm trying to run Rails tests on Azure Postgres, which does not allow superuser), would you kindly tell me where this parameter is and what to change it to? |
Same question here |
@felixwatts @ASing0 This is just a suggestion, but if you've hit a bug running the rails test suite, it's preferable to open a new ticket with a reproducible test case than comment asking for help on a 5 year old PR. Alternatively, you can ask as many questions you want on the discuss. 🙇 |
Re-create #21233
eeac615 was reverted (127509c) because it breaks tests.
ref: 72c1557
context: #5523
Other Information
authors
fixture withauthor_addresses
because of its foreign key constraint.ALTER CONSTRAINTS
and fixed in 9.4.2.