Class: Qa::Authorities::Local::MysqlTableBasedAuthority

Inherits:
TableBasedAuthority show all
Defined in:
lib/qa/authorities/local/mysql_table_based_authority.rb

Instance Attribute Summary

Attributes inherited from TableBasedAuthority

#subauthority

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TableBasedAuthority

#all, #find, #initialize

Methods inherited from Base

#all, #find

Constructor Details

This class inherits a constructor from Qa::Authorities::Local::TableBasedAuthority

Class Method Details

.check_for_indexObject



7
8
9
10
11
12
13
14
15
# File 'lib/qa/authorities/local/mysql_table_based_authority.rb', line 7

def self.check_for_index
  if table_or_view_exists? && index_name_exists? # rubocop:disable Style/GuardClause
    Rails.logger.error "You've installed mysql local authority tables, but you haven't indexed the lower label. "
    "Rails doesn't support functional indexes in migrations, so we tried to execute it for you but something went wrong...\n" \
    "Make sure your table has a lower_label column, which is virtually created, and that the column is indexed." \
    " ALTER TABLE #{table_name} ADD lower_label VARCHAR(256) GENERATED ALWAYS AS (lower(label)) VIRTUAL" \
    " CREATE INDEX #{table_index} ON #{table_name} (local_authority_id, lower_label)"
  end
end

Instance Method Details

#search(q) ⇒ Object



17
18
19
20
# File 'lib/qa/authorities/local/mysql_table_based_authority.rb', line 17

def search(q)
  return [] if q.blank?
  output_set(base_relation.where('lower_label like ?', "#{q.downcase}%").limit(25))
end