Class: RuboCop::Cop::Oracle::OnlineIndex

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/oracle/online_index.rb

Overview

Checks for uses options: online option on add_index. The ONLINE option is required if you want to run with OLTP when indexing migration in Oracle. By specifying MigratedSchemaVersion option, migration files that have been migrated can be ignored.

Examples:


# bad
add_index :table_name, :column_name

# good
add_index :table_name, :column_name, options: :online

MigratedSchemaVersion: '202104130150'


# bad - Migration files higher than '202104130150' will be registered an offense.
add_index :table_name, :column_name

# good - Migration files lower than or equal to '202104130150' will be ignored.
add_index :table_name, :column_name

Constant Summary collapse

MSG =
'Specify `options: :online` option to `add_index`.'
RESTRICT_ON_SEND =
%i[add_index].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/rubocop/cop/oracle/online_index.rb', line 32

def on_send(node)
  return if already_migrated_file? || use_online_option?(node.last_argument)

  add_offense(node.loc.selector) do |corrector|
    corrector.insert_after(node, ', options: :online')
  end
end