Merge branch '15296-cwl-cancel-procs' closes #15296
[arvados.git] / services / api / db / migrate / 20161213172944_full_text_search_indexes.rb
index 4cb4d978a1bfb909ed8984c4622910c2308206e4..55ab7115757d6fb3042f9bdd8c85e1ea92bc3049 100644 (file)
@@ -1,4 +1,8 @@
-class FullTextSearchIndexes < ActiveRecord::Migration
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class FullTextSearchIndexes < ActiveRecord::Migration[4.2]
   def fts_indexes
     {
       "collections" => "collections_full_text_search_idx",
@@ -11,16 +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|
-      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