8784: Fix test for latest firefox.
[arvados.git] / services / api / db / migrate / 20161213172944_full_text_search_indexes.rb
1 class FullTextSearchIndexes < ActiveRecord::Migration
2   def fts_indexes
3     {
4       "collections" => "collections_full_text_search_idx",
5       "container_requests" => "container_requests_full_text_search_idx",
6       "groups" => "groups_full_text_search_idx",
7       "jobs" => "jobs_full_text_search_idx",
8       "pipeline_instances" => "pipeline_instances_full_text_search_idx",
9       "pipeline_templates" => "pipeline_templates_full_text_search_idx",
10       "workflows" => "workflows_full_text_search_idx",
11     }
12   end
13
14   def up
15     # remove existing fts indexes and create up to date ones with no leading space
16     fts_indexes.each do |t, i|
17       t.classify.constantize.reset_column_information
18       ActiveRecord::Base.connection.indexes(t).each do |idx|
19         if idx.name == i
20           remove_index t.to_sym, :name => i
21           break
22         end
23       end
24       execute "CREATE INDEX #{i} ON #{t} USING gin(#{t.classify.constantize.full_text_tsvector});"
25     end
26   end
27
28   def down
29     fts_indexes.each do |t, i|
30       remove_index t.to_sym, :name => i
31     end
32   end
33 end