Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20150122175935_no_description_in_search_index.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 # If the database reflects an obsolete version of the 20141208185217
6 # migration (i.e., before commit:5c1db683), revert it and reapply the
7 # current version. (The down-migration is the same in both versions.)
8
9 require "./db/migrate/20141208185217_search_index.rb"
10
11 class NoDescriptionInSearchIndex < ActiveRecord::Migration
12   def up
13     all_tables = %w{collections groups jobs pipeline_instances pipeline_templates}
14     all_tables.each do |table|
15       indexes = ActiveRecord::Base.connection.indexes(table)
16       search_index_by_name = indexes.select do |index|
17         index.name == "#{table}_search_index"
18       end
19
20       if !search_index_by_name.empty?
21         index_columns = search_index_by_name.first.columns
22         has_description = index_columns.include? 'description'
23         if has_description
24           SearchIndex.new.migrate(:down)
25           SearchIndex.new.migrate(:up)
26           break
27         end
28       end
29     end
30   end
31
32   def down
33   end
34 end