Class: RuboCop::Cop::Migration::AddIndexConcurrently
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Migration::AddIndexConcurrently
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, Migration::CopConcerns::DisableDdlTransaction
- Defined in:
- lib/rubocop/cop/migration/add_index_concurrently.rb
Overview
Use ‘algorithm: :concurrently` on adding indexes to existing tables in PostgreSQL.
To avoid blocking writes.
Constant Summary collapse
- MSG =
'Use `algorithm: :concurrently` on adding indexes to existing tables in PostgreSQL.'- MESSAGE_FOR_DUPLICATED_DISABLE_DDL_TRANSACTION =
'Remove duplicated `disable_ddl_transaction!`.'- RESTRICT_ON_SEND =
%i[ add_index index ].freeze
Instance Method Summary collapse
- #on_send(node) ⇒ void (also: #on_csend)
Methods included from Migration::CopConcerns::DisableDdlTransaction
Instance Method Details
#on_send(node) ⇒ void Also known as: on_csend
This method returns an undefined value.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rubocop/cop/migration/add_index_concurrently.rb', line 46 def on_send(node) if add_index_without_concurrency?(node) add_offense(node) do |corrector| autocorrect(corrector, node) end end duplicated_disable_ddl_transactions_from(node).each do |disable_ddl_transactions_node| add_offense(node, message: MESSAGE_FOR_DUPLICATED_DISABLE_DDL_TRANSACTION) do |corrector| corrector.remove( range_with_surrounding_space( disable_ddl_transactions_node.source_range, side: :left ) ) end end end |