766060bcdf
This adds a Rubocop rule to enforce the use of add_concurrent_foreign_key instead of the regular add_foreign_key method. This cop has been disabled for existing migrations so we don't need to change those.
27 lines
666 B
Ruby
27 lines
666 B
Ruby
require_relative '../../migration_helpers'
|
|
|
|
module RuboCop
|
|
module Cop
|
|
module Migration
|
|
# Cop that checks if `add_concurrent_foreign_key` is used instead of
|
|
# `add_foreign_key`.
|
|
class AddConcurrentForeignKey < RuboCop::Cop::Cop
|
|
include MigrationHelpers
|
|
|
|
MSG = '`add_foreign_key` requires downtime, use `add_concurrent_foreign_key` instead'
|
|
|
|
def on_send(node)
|
|
return unless in_migration?(node)
|
|
|
|
name = node.children[1]
|
|
|
|
add_offense(node, :selector) if name == :add_foreign_key
|
|
end
|
|
|
|
def method_name(node)
|
|
node.children.first
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|