4523: add a new migration script that invokes search_index migration down and up...
[arvados.git] / services / api / db / migrate / 20150122175935_no_description_in_search_index.rb
1 require "./db/migrate/20141208185217_search_index.rb"
2
3 class NoDescriptionInSearchIndex < ActiveRecord::Migration
4   def change
5     all_tables = %w{collections groups jobs pipeline_instances pipeline_templates}
6     all_tables.each do |table|
7       indexes = ActiveRecord::Base.connection.indexes(table)
8       search_index_by_name = indexes.select do |index|
9         index.name == "#{table}_search_index"
10       end
11
12       index_columns = search_index_by_name.first.andand.columns
13       has_description = index_columns.select.each do |column|
14         column == 'description'
15       end
16
17       if !has_description.empty?
18         SearchIndex.new.migrate(:down)
19         SearchIndex.new.migrate(:up)
20         break
21       end
22     end
23   end
24 end