8784: Fix test for latest firefox.
[arvados.git] / services / api / db / migrate / 20150526180251_leading_space_on_full_text_index.rb
1 require "./db/migrate/20150123142953_full_text_search.rb"
2
3 class LeadingSpaceOnFullTextIndex < ActiveRecord::Migration
4   def up
5     # Inspect one of the full-text indexes (chosen arbitrarily) to
6     # determine whether this migration is needed.
7     ft_index_name = 'jobs_full_text_search_idx'
8     ActiveRecord::Base.connection.indexes('jobs').each do |idx|
9       if idx.name == ft_index_name
10         if idx.columns.first.index "((((' '"
11           # Index is already correct. This happens if the source tree
12           # already had the new version of full_text_tsvector by the
13           # time the initial FullTextSearch migration ran.
14           $stderr.puts "This migration is not needed."
15         else
16           # Index was created using the old full_text_tsvector. Drop
17           # and re-create all full text indexes.
18           FullTextSearch.new.migrate(:down)
19           FullTextSearch.new.migrate(:up)
20         end
21         return
22       end
23     end
24     raise "Did not find index '#{ft_index_name}'. Earlier migration missed??"
25   end
26
27   def down
28     $stderr.puts <<EOS
29 Down-migration is not supported for this change, and might be unnecessary.
30
31 If you run a code base older than 20150526180251 against this
32 database, full text search will be slow even on collections where it
33 used to work well. If this is a concern, first check out the desired
34 older version of the code base, and then run
35 "rake db:migrate:down VERSION=20150123142953"
36 followed by
37 "rake db:migrate:up VERSION=20150123142953"
38 .
39 EOS
40   end
41 end