debian-mirror-gitlab/rubocop/cop/migration/remove_column.rb

33 lines
880 B
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require_relative '../../migration_helpers'
module RuboCop
module Cop
module Migration
# Cop that checks if remove_column is used in a regular (not
# post-deployment) migration.
class RemoveColumn < RuboCop::Cop::Cop
include MigrationHelpers
2021-04-29 21:17:54 +05:30
MSG = '`remove_column` must only be used in post-deployment migrations'
2018-03-17 18:26:18 +05:30
def on_def(node)
def_method = node.children[0]
return unless in_migration?(node) && !in_post_deployment_migration?(node)
return unless def_method == :change || def_method == :up
node.each_descendant(:send) do |send_node|
send_method = send_node.children[1]
if send_method == :remove_column
add_offense(send_node, location: :selector)
end
end
end
end
end
end
end