diff options
Diffstat (limited to 'rubocop/cop/migration/add_column_with_default.rb')
-rw-r--r-- | rubocop/cop/migration/add_column_with_default.rb | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/rubocop/cop/migration/add_column_with_default.rb b/rubocop/cop/migration/add_column_with_default.rb index 383653ef5a5..355319b0dfe 100644 --- a/rubocop/cop/migration/add_column_with_default.rb +++ b/rubocop/cop/migration/add_column_with_default.rb @@ -5,39 +5,17 @@ require_relative '../../migration_helpers' module RuboCop module Cop module Migration - # Cop that checks if columns are added in a way that doesn't require - # downtime. class AddColumnWithDefault < RuboCop::Cop::Cop include MigrationHelpers - MSG = '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, ' \ - 'see https://gitlab.com/gitlab-org/gitlab/issues/38060'.freeze - - def_node_matcher :add_column_with_default?, <<~PATTERN - (send _ :add_column_with_default $_ ... (hash $...)) - PATTERN + MSG = '`add_column_with_default` is deprecated, use `add_column` instead'.freeze def on_send(node) return unless in_migration?(node) - add_column_with_default?(node) do |table, options| - add_offense(node, location: :selector) if offensive?(table, options) - end - end - - private - - def offensive?(table, options) - table_blacklisted?(table) && !nulls_allowed?(options) - end - - def nulls_allowed?(options) - options.find { |opt| opt.key.value == :allow_null && opt.value.true_type? } - end + name = node.children[1] - def table_blacklisted?(symbol) - symbol && symbol.type == :sym && - BLACKLISTED_TABLES.include?(symbol.children[0]) + add_offense(node, location: :selector) if name == :add_column_with_default end end end |