Welcome to mirror list, hosted at ThFree Co, Russian Federation.

add_concurrent_foreign_key.rb « migration « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e40a7087a4710dfead0bb00cc2a4ee342b2db6c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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