Class: RuboCop::Cop::Sequel::IrreversibleMigration

Inherits:
Base
  • Object
show all
Includes:
Helpers::Migration
Defined in:
lib/rubocop/cop/sequel/irreversible_migration.rb

Overview

IrreversibleMigration looks for methods inside a ‘change` block that cannot be reversed.

Constant Summary collapse

VALID_CHANGE_METHODS =
%i[
  create_table
  create_join_table
  create_view
  add_column
  add_index
  rename_column
  rename_table
  alter_table
  add_column
  add_constraint
  add_foreign_key
  add_primary_key
  add_index
  add_full_text_index
  add_spatial_index
  rename_column
  set_column_allow_null
].freeze
MSG =
'Using "%<name>s" inside a "change" block may cause an irreversible migration. Use "up" & "down" instead.'
PRIMARY_KEY_MSG =
'Avoid using "add_primary_key" with an array argument inside a "change" block.'

Instance Method Summary collapse

Methods included from Helpers::Migration

#within_sequel_migration?

Instance Method Details

#on_block(node) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rubocop/cop/sequel/irreversible_migration.rb', line 34

def on_block(node)
  return unless node.method_name == :change
  return unless within_sequel_migration?(node)

  body = node.body
  return unless body

  body.each_node(:send) { |child_node| validate_node(child_node) }
end