Class: RuboCop::Cop::Migrations::RemoveIndex

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/migrations/remove_index.rb

Overview

Removing indexes is dangerous by nature, if the index you remove is used extensively, you could end up with database degradation.

This disallow the use of remove_index at all. It is only allowed inside a down method definition. If you actually know what you are doing (usually when the index is not being used) you should explicitly disable the check by adding a “rubocop:disable Migrations/RemoveIndex“ comment in the offending line

Constant Summary collapse

MSG =
'remove_index is disallowed'.freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/rubocop/cop/migrations/remove_index.rb', line 17

def on_send(node)
  remove_index_found(node) do
    node.each_ancestor do |a|
      next unless a.def_type?
      if a.to_s =~ /def :up/ || a.to_s =~ /def :change/
        add_offense(node, :selector, MSG)
      end
    end
  end
end