class RuboCop::Cop::Oracle::OnlineIndex
This cop 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.
@example
# bad add_index :table_name, :column_name # good add_index :table_name, :column_name, options: :online
@example 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
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/oracle/online_index.rb, line 33 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
Private Instance Methods
already_migrated_file?()
click to toggle source
# File lib/rubocop/cop/oracle/online_index.rb, line 43 def already_migrated_file? schema_version = File.basename(processed_source.file_path).match(/(?<timestamp>\d{12})/)['timestamp'] return false unless migrated_schema_version schema_version <= migrated_schema_version # Ignore applied migration files. end
migrated_schema_version()
click to toggle source
# File lib/rubocop/cop/oracle/online_index.rb, line 60 def migrated_schema_version cop_config.fetch('MigratedSchemaVersion', nil) end
use_online_option?(options)
click to toggle source
# File lib/rubocop/cop/oracle/online_index.rb, line 50 def use_online_option?(options) if options.hash_type? options.each_pair do |key, value| return true if key.source.match?(/\A:?options\z/i) && value.source.match?(/\A:?online\z/i) end end false end