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

Projects
None yet
5 participants
@jychen7
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Aug 5, 2018

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.

rails-bot commented Aug 5, 2018

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.

@nicktime

This comment has been minimized.

Show comment
Hide comment
@nicktime

nicktime Aug 5, 2018

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?

nicktime commented Aug 5, 2018

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

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 5, 2018

Contributor

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?

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 5, 2018

Member

I restarted the failing job

Member

schneems commented Aug 5, 2018

I restarted the failing job

@jychen7

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 5, 2018

Contributor

@schneems thanks

Contributor

jychen7 commented Aug 5, 2018

@schneems thanks

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 5, 2018

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 5, 2018

Contributor

@schneems I just squash and force push.

Contributor

jychen7 commented Aug 5, 2018

@schneems I just squash and force push.

@kamipo

This comment has been minimized.

Show comment
Hide comment
@kamipo
Member

kamipo commented Aug 5, 2018

@jychen7

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 6, 2018

Contributor

@kamipo commit message is updated to use real author name

Contributor

jychen7 commented Aug 6, 2018

@kamipo commit message is updated to use real author name

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 6, 2018

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 6, 2018

Contributor

@schneems @kamipo changelog is added.

ps: looks like changelog is easier to conflic

Contributor

jychen7 commented Aug 6, 2018

@schneems @kamipo changelog is added.

ps: looks like changelog is easier to conflic

@jychen7

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 8, 2018

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 9, 2018

Contributor

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
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 9, 2018

Member

I restarted the tests

Member

schneems commented Aug 9, 2018

I restarted the tests

@jychen7

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 9, 2018

Contributor

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

Contributor

jychen7 commented Aug 9, 2018

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

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 9, 2018

Member

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

Member

schneems commented Aug 9, 2018

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

@jychen7

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 10, 2018

Contributor

@schneems thanks, I rebase and force push.

only one job fail, need restart this time

Contributor

jychen7 commented Aug 10, 2018

@schneems thanks, I rebase and force push.

only one job fail, need restart this time

Allow `to_table` in `invert_remove_foreign_key`
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

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 14, 2018

Contributor

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

Contributor

jychen7 commented Aug 14, 2018

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

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 14, 2018

Member

Thanks!

Member

schneems commented Aug 14, 2018

Thanks!

@schneems schneems merged commit d54435b into rails:master Aug 14, 2018

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Aug 14, 2018

Follow up rails#33530
- 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 referenced this pull request Aug 14, 2018

Merged

Follow up #33530 #33617

georgeclaghorn added a commit that referenced this pull request Aug 15, 2018

@jychen7

This comment has been minimized.

Show comment
Hide comment
@jychen7

jychen7 Aug 15, 2018

Contributor

@schneems thanks

Contributor

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