11908: Migrate collections.properties to jsonb.
[arvados.git] / services / api / db / migrate / 20161213172944_full_text_search_indexes.rb
index 3f484b4c31db48076b3385bc885d077cdcb84733..0ec52124deca9eba478da8f4799d1f2e62c34e59 100644 (file)
@@ -15,17 +15,18 @@ class FullTextSearchIndexes < ActiveRecord::Migration
     }
   end
 
+  def replace_index(t)
+    i = fts_indexes[t]
+    t.classify.constantize.reset_column_information
+    execute "DROP INDEX IF EXISTS #{i}"
+    execute "CREATE INDEX #{i} ON #{t} USING gin(#{t.classify.constantize.full_text_tsvector})"
+  end
+
   def up
-    # remove existing fts indexes and create up to date ones with no leading space
-    fts_indexes.each do |t, i|
-      t.classify.constantize.reset_column_information
-      ActiveRecord::Base.connection.indexes(t).each do |idx|
-        if idx.name == i
-          remove_index t.to_sym, :name => i
-          break
-        end
-      end
-      execute "CREATE INDEX #{i} ON #{t} USING gin(#{t.classify.constantize.full_text_tsvector});"
+    # remove existing fts indexes and create up to date ones with no
+    # leading space
+    fts_indexes.keys.each do |t|
+      replace_index(t)
     end
   end