Skip to content
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

33515 invert remove foreign key support "to_table" #33530

Merged
merged 1 commit into from Aug 14, 2018

Conversation

jychen7
Copy link
Contributor

@jychen7 jychen7 commented Aug 5, 2018

Summary

remove_foreign_key supports

  • remove_foreign_key :accounts, :branches
  • remove_foreign_key :accounts, to_table: :branches

but the second one is not reversible.

This branch is to fix and allow second one to be reversible.

Other Information

close #33515
continuing #33519, base on discussion between @NickTime and @sikachu

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kamipo (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@n-epifanov
Copy link

Pls, add info on :to_table option, it's missing, something like

diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 9d46eb5..7e54340 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -988,7 +988,10 @@ def add_foreign_key(from_table, to_table, options = {})
       #
       #   remove_foreign_key :accounts, name: :special_fk_name
       #
-      # The +options+ hash accepts the same keys as SchemaStatements#add_foreign_key.
+      # The +options+ hash accepts the same keys as SchemaStatements#add_foreign_key
+      # with an addition of
+      # [<tt>:to_table</tt>]
+      # +to_table+ contains the referenced primary key.
       def remove_foreign_key(from_table, options_or_to_table = {})
         return unless supports_foreign_keys?

@jychen7
Copy link
Contributor Author

jychen7 commented Aug 5, 2018

CI

All GREEN except only one job

No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received
The build has been terminated

How to rerun?

@schneems
Copy link
Member

schneems commented Aug 5, 2018

I restarted the failing job

@jychen7
Copy link
Contributor Author

jychen7 commented Aug 5, 2018

@schneems thanks

@schneems
Copy link
Member

schneems commented Aug 5, 2018

Everything looks good. Can you squash to one commit. You can give credit to multiple authors using this technique https://contributors.rubyonrails.org/faq

@jychen7 jychen7 force-pushed the 33515-invert-remove-foreign-key branch from 91634d9 to 54ef924 Compare August 5, 2018 16:38
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 5, 2018

@schneems I just squash and force push.

@kamipo
Copy link
Member

kamipo commented Aug 5, 2018

The real author name of #33519 is Nikolay Epifanov.

https://patch-diff.githubusercontent.com/raw/rails/rails/pull/33519.patch

@jychen7 jychen7 force-pushed the 33515-invert-remove-foreign-key branch 2 times, most recently from ee4f4af to 3692f93 Compare August 6, 2018 02:45
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 6, 2018

@kamipo commit message is updated to use real author name

@schneems
Copy link
Member

schneems commented Aug 6, 2018

Looking good. I forgot to mention that this is going to need a changelog since it’s a change in functionality.

After that I think we are good to go. Thanks again for this.

@jychen7 jychen7 force-pushed the 33515-invert-remove-foreign-key branch from 3692f93 to a4a1914 Compare August 6, 2018 06:01
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 6, 2018

@schneems @kamipo changelog is added.

ps: looks like changelog is easier to conflic

@jychen7
Copy link
Contributor Author

jychen7 commented Aug 8, 2018

@schneems @kamipo sorry, will merge soon? need any update from me?

@jychen7 jychen7 closed this Aug 8, 2018
@jychen7 jychen7 reopened this Aug 8, 2018
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 9, 2018

CI was green. No code changes in this branch.
I close the PR by accident, then re-open it, the CI failed at i18n?

Failure:
ApplicationTests::I18nTest#test_config.i18n.fallbacks.map_=_{_:ca_=>_:'es-ES'_}_initializes_fallbacks_with_a_mapping_ca_=>_es-ES [test/application/initializers/i18n_test.rb:240]:
expected fallbacks for :ca to be [:ca, :"es-ES", :es, :en], but were [:ca, :"es-ES", :es].
Expected: [:ca, :"es-ES", :es, :en]
  Actual: [:ca, :"es-ES", :es]
rails test test/application/initializers/i18n_test.rb:237

@schneems
Copy link
Member

schneems commented Aug 9, 2018

I restarted the tests

@jychen7
Copy link
Contributor Author

jychen7 commented Aug 9, 2018

@schneems thanks, but I think restart doesn't work, need #33566

@schneems
Copy link
Member

schneems commented Aug 9, 2018

Since that's merged can you rebase and re-push?

@jychen7 jychen7 force-pushed the 33515-invert-remove-foreign-key branch from a4a1914 to 1da0f7e Compare August 10, 2018 02:52
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 10, 2018

@schneems thanks, I rebase and force push.

only one job fail, need restart this time

@jychen7 jychen7 force-pushed the 33515-invert-remove-foreign-key branch from 1da0f7e to c0758d4 Compare August 11, 2018 11:00
remove_foreign_key supports
- remove_foreign_key :accounts, :branches
- remove_foreign_key :accounts, to_table: :branches

but the second one is not reversible.

This branch is to fix and allow second one to be reversible.

[Nikolay Epifanov, Rich Chen]
@jychen7 jychen7 force-pushed the 33515-invert-remove-foreign-key branch from c0758d4 to 6b9948c Compare August 14, 2018 13:52
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 14, 2018

@schneems @kamipo CI green now, ready to merge?

@schneems
Copy link
Member

Thanks!

@schneems schneems merged commit d54435b into rails:master Aug 14, 2018
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Aug 14, 2018
- Move changelog entry of rails#33530 up in order to preserve the chronology
  since we always add new entries on the top of a changelog file.
- Clarify the changelog entry
- Clarify the docs of remove_foreign_key
- Ensure reversible of `remove_foreign_key` with `:primary_key` and `:to_table`
  options.
@bogdanvlviv bogdanvlviv mentioned this pull request Aug 14, 2018
georgeclaghorn added a commit that referenced this pull request Aug 15, 2018
@jychen7
Copy link
Contributor Author

jychen7 commented Aug 15, 2018

@schneems thanks

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.

remove_foreign_key is not reversible
5 participants