X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/55aafbb07904ca24390dd47ea960eae7cb2b909a..d56b21609ddd2e2e096f5c30e991d24aa213f7f4:/services/api/db/migrate/20161213172944_full_text_search_indexes.rb diff --git a/services/api/db/migrate/20161213172944_full_text_search_indexes.rb b/services/api/db/migrate/20161213172944_full_text_search_indexes.rb index 3f484b4c31..55ab711575 100644 --- a/services/api/db/migrate/20161213172944_full_text_search_indexes.rb +++ b/services/api/db/migrate/20161213172944_full_text_search_indexes.rb @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: AGPL-3.0 -class FullTextSearchIndexes < ActiveRecord::Migration +class FullTextSearchIndexes < ActiveRecord::Migration[4.2] def fts_indexes { "collections" => "collections_full_text_search_idx", @@ -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