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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
873 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.
2022-10-11 01:57:18 +05:30
class RemoveColumn < RuboCop::Cop::Base
2018-03-17 18:26:18 +05:30
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
2022-10-11 01:57:18 +05:30
add_offense(send_node.loc.selector)
2018-03-17 18:26:18 +05:30
end
end
end
end
end
end
end