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

[Fix #604] Remove remove_reference checks from Rails/ReversibleMigration #606

Merged

Conversation

TonyArra
Copy link
Contributor

@TonyArra TonyArra commented Dec 27, 2021

Fixes #604

This removes the new check for remove_reference in Rails/ReversibleMigration (#592), as well as the recently added check for remove_belongs_to - an alias of remove_reference.

As discussed in #604, both of these statements are reversible, since their inverse methods are included in ActiveRecord::Migration::CommandRecorder

It is true that any options that were used in the add_reference/add_belongs_to statements need to also be included in the remove_reference statement; otherwise, a rollback will not properly restore the schema back to its previous state; however, the same could be said of several other reversible statements, such as remove_column.

For example, if I add a column with additional options, like default:

    add_column :comments, :position, :integer, default: 0

and then later remove that column without specifying those same options

    remove_column :comments, :position, :integer

then a rollback will not properly revert the schema to its previous state; it will be missing the default option.

Since there is no simple way to check that all of the options on an index, foreign key, constraint, or column are present in the remove_* statement, it seems impractical to have a cop for these methods. It will most likely result in more users disabling the cop entirely.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@TonyArra TonyArra changed the title [Fix #604] Remove remove_reference checks from Rails/ReversibleMigration [Fix #604] Remove remove_reference checks from Rails/ReversibleMigration Dec 27, 2021
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Thanks!

@koic
Copy link
Member

koic commented Dec 28, 2021

Can you add the changelog entry and squash your commits into one?

Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@TonyArra TonyArra force-pushed the reversible-migration-remove-reference branch 5 times, most recently from 746bf56 to e713820 Compare December 28, 2021 14:22
@TonyArra
Copy link
Contributor Author

TonyArra commented Dec 28, 2021

@koic done
Edit: appended implicit profile link to CHANGELOG.md

…ibleMigration`

This reverts commit 798b39e.

Remove `belongs_to` and `remove_reference` checks from `Rails/ReversibleMigration`.
@TonyArra TonyArra force-pushed the reversible-migration-remove-reference branch from e713820 to bf3d379 Compare December 28, 2021 14:30
@koic koic merged commit d8d4489 into rubocop:master Jan 5, 2022
@koic
Copy link
Member

koic commented Jan 5, 2022

Thanks!

@TonyArra TonyArra deleted the reversible-migration-remove-reference branch January 5, 2022 14:41
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.

ReversibleMigration: remove_reference is not reversible.
3 participants