1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class AddTrigramIndexForTextSearch < ActiveRecord::Migration[5.0]
8 "collections" => "collections_trgm_text_search_idx",
9 "container_requests" => "container_requests_trgm_text_search_idx",
10 "groups" => "groups_trgm_text_search_idx",
11 "jobs" => "jobs_trgm_text_search_idx",
12 "pipeline_instances" => "pipeline_instances_trgm_text_search_idx",
13 "pipeline_templates" => "pipeline_templates_trgm_text_search_idx",
14 "workflows" => "workflows_trgm_text_search_idx",
20 execute "CREATE EXTENSION IF NOT EXISTS pg_trgm"
21 rescue ActiveRecord::StatementInvalid => e
22 puts "Cannot create the pg_trgm extension."
23 if e.cause.is_a?(PG::InsufficientPrivilege)
24 puts "The user must have a SUPERUSER role."
25 elsif e.cause.is_a?(PG::UndefinedFile)
26 puts "The postgresql-contrib package is most likely not installed."
30 puts "Please visit https://doc.arvados.org/admin/upgrading.html for instructions on how to run this migration."
34 trgm_indexes.each do |model, indx|
35 execute "CREATE INDEX #{indx} ON #{model} USING gin((#{model.classify.constantize.full_text_trgm}) gin_trgm_ops)"
40 trgm_indexes.each do |_, indx|
41 execute "DROP INDEX IF EXISTS #{indx}"