X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d13cc16ebbe287fe81d06c5faa1d15fe588bcf16..1a599ec69ad8d533da1f12ad5d2c5789aa1c14e2:/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 4cb4d978a1..55ab711575 100644 --- a/services/api/db/migrate/20161213172944_full_text_search_indexes.rb +++ b/services/api/db/migrate/20161213172944_full_text_search_indexes.rb @@ -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