class Scenic::Adapters::Oracle::IndexReapplication

Attributes

connection[R]
speaker[R]

Public Class Methods

new(connection:, speaker: ActiveRecord::Migration) click to toggle source
# File lib/scenic/adapters/oracle/index_reapplication.rb, line 7
def initialize(connection:, speaker: ActiveRecord::Migration)
  @connection = connection
  @speaker = speaker
end

Public Instance Methods

on(name) { || ... } click to toggle source
# File lib/scenic/adapters/oracle/index_reapplication.rb, line 12
def on(name)
  indexes = Indexes.new(connection: connection).on(name)

  yield

  indexes.each(&method(:try_index_create))
end

Private Instance Methods

object_columns(name) click to toggle source
# File lib/scenic/adapters/oracle/index_reapplication.rb, line 40
        def object_columns(name)
          connection.select_values(<<-EOSQL)
            select lower(column_name)
            from user_tab_cols
            where table_name = '#{name}'
          EOSQL
        end
say(message) click to toggle source
# File lib/scenic/adapters/oracle/index_reapplication.rb, line 48
def say(message)
  subitem = true
  speaker.say(message, subitem)
end
try_index_create(index) click to toggle source
# File lib/scenic/adapters/oracle/index_reapplication.rb, line 24
def try_index_create(index)
  if valid_index?(index)
    connection.execute(index.definition) &&
      say("index '#{index.index_name}' on '#{index.object_name}' has been recreated")
  else
    say "index '#{index.index_name}' on '#{index.object_name}' is no longer valid and has been dropped."
  end
end
valid_index?(index) click to toggle source
# File lib/scenic/adapters/oracle/index_reapplication.rb, line 33
def valid_index?(index)
  object_columns = Set.new(object_columns(index.object_name))
  index_columns = Set.new(index.columns)

  index_columns.subset?(object_columns)
end