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

Rubocop is accusing remove_reference as a not reversible migration #640

Closed
3 tasks
andrer0cha opened this issue Feb 11, 2022 · 1 comment
Closed
3 tasks
Labels
duplicate This issue or pull request already exists

Comments

@andrer0cha
Copy link

Expected behavior

The remove_reference command should be considered as reversible

Actual behavior

The remove_reference command is not considered as reversible

Describe here what actually happened.

I created a migration to remove a reference from one table to another, as shown below:

# frozen_string_literal: true

class DropColumnFromMyTable < ActiveRecord::Migration[6.1]
  def change
    remove_reference :my_table, :my_other_table, foreign_key: true, index: true
  end
end

When running rubocop, it accused that my migration is not reversible. However, I've tested a few times migrating, rolling it back and comparing the results.
From my tests, all the indexes, keys and references were created a dropped as expected.

Steps to reproduce the problem

  • Create a migration with rails g migration MigrationName
  • Try removing a reference from an existing table using remove reference
    example: remove_reference :my_table, :my_other_table, foreign_key: true, index: true
  • Try running rubocop on the created migration and check that it accuses:
    Rails/ReversibleMigration: remove_reference is not reversible.

RuboCop version

$ rubocop -V
1.24.1 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 3.0.3 x86_64-darwin20)
  - rubocop-performance 1.13.1
  - rubocop-rails 2.13.0
  - rubocop-rspec 2.7.0
@koic koic transferred this issue from rubocop/rubocop Feb 11, 2022
@fatkodima
Copy link
Contributor

Works as expected on the latest version. Duplicate of #604

@koic koic added the duplicate This issue or pull request already exists label Apr 14, 2022
@koic koic closed this as completed Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants