Merge branch '14873-api-rails5-upgrade'
[arvados.git] / services / api / db / migrate / 20170706141334_json_collection_properties.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require './db/migrate/20161213172944_full_text_search_indexes'
6
7 class JsonCollectionProperties < ActiveRecord::Migration[4.2]
8   def up
9     # Drop the FT index before changing column type to avoid
10     # "PG::DatatypeMismatch: ERROR: COALESCE types jsonb and text
11     # cannot be matched".
12     ActiveRecord::Base.connection.execute 'DROP INDEX IF EXISTS collections_full_text_search_idx'
13     ActiveRecord::Base.connection.execute 'ALTER TABLE collections ALTER COLUMN properties TYPE jsonb USING properties::jsonb'
14     FullTextSearchIndexes.new.replace_index('collections')
15   end
16
17   def down
18     ActiveRecord::Base.connection.execute 'ALTER TABLE collections ALTER COLUMN properties TYPE text'
19   end
20 end