Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20170216170823_no_cr_mounts_and_workflow_def_in_full_text_search_index.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class NoCrMountsAndWorkflowDefInFullTextSearchIndex < ActiveRecord::Migration
6   def fts_indexes
7     {
8       "container_requests" => "container_requests_full_text_search_idx",
9       "workflows" => "workflows_full_text_search_idx",
10     }
11   end
12
13   def up
14     # remove existing fts index and recreate for container_requests and workflows
15     fts_indexes.each do |t, i|
16       t.classify.constantize.reset_column_information
17       ActiveRecord::Base.connection.indexes(t).each do |idx|
18         if idx.name == i
19           remove_index t.to_sym, :name => i
20           break
21         end
22       end
23       execute "CREATE INDEX #{i} ON #{t} USING gin(#{t.classify.constantize.full_text_tsvector});"
24     end
25   end
26
27   def down
28     fts_indexes.each do |t, i|
29       t.classify.constantize.reset_column_information
30       ActiveRecord::Base.connection.indexes(t).each do |idx|
31         if idx.name == i
32           remove_index t.to_sym, :name => i
33           break
34         end
35       end
36     end
37   end
38 end