2021-02-11 16:09:00 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-05 18:53:57 -04:00
|
|
|
require_relative '../../migration_helpers'
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module Migration
|
|
|
|
# Cop that checks if indexes are removed in a concurrent manner.
|
2022-09-14 11:12:56 -04:00
|
|
|
class RemoveIndex < RuboCop::Cop::Base
|
2017-04-05 18:53:57 -04:00
|
|
|
include MigrationHelpers
|
|
|
|
|
2021-03-23 08:09:33 -04:00
|
|
|
MSG = '`remove_index` requires downtime, use `remove_concurrent_index` instead'
|
2017-04-05 18:53:57 -04:00
|
|
|
|
|
|
|
def on_def(node)
|
|
|
|
return unless in_migration?(node)
|
|
|
|
|
|
|
|
node.each_descendant(:send) do |send_node|
|
2022-09-14 11:12:56 -04:00
|
|
|
add_offense(send_node.loc.selector) if method_name(send_node) == :remove_index
|
2017-04-05 18:53:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_name(node)
|
|
|
|
node.children[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|