Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20170105160301_add_output_name_to_cr_fts_index.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class AddOutputNameToCrFtsIndex < ActiveRecord::Migration
6   def up
7     t = "container_requests"
8     i = "container_requests_full_text_search_idx"
9     t.classify.constantize.reset_column_information
10     ActiveRecord::Base.connection.indexes(t).each do |idx|
11       if idx.name == i
12         remove_index t.to_sym, :name => i
13         break
14       end
15     end
16     # By now, container_request should have the new column "output_name" so full_text_tsvector
17     # would include it on its results
18     execute "CREATE INDEX #{i} ON #{t} USING gin(#{t.classify.constantize.full_text_tsvector});"
19   end
20
21   def down
22     t = "container_requests"
23     i = "container_requests_full_text_search_idx"
24     remove_index t.to_sym, :name => i
25   end
26 end