Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20150206230342_rename_replication_attributes.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class RenameReplicationAttributes < ActiveRecord::Migration
6   RENAME = [[:redundancy, :replication_desired],
7             [:redundancy_confirmed_as, :replication_confirmed],
8             [:redundancy_confirmed_at, :replication_confirmed_at]]
9
10   def up
11     RENAME.each do |oldname, newname|
12       rename_column :collections, oldname, newname
13     end
14     remove_column :collections, :redundancy_confirmed_by_client_uuid
15     Collection.reset_column_information
16
17     # Removing that column dropped some search indexes. Let's put them back.
18     add_index :collections, ["owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "portable_data_hash", "uuid", "name", "file_names"], name: 'collections_search_index'
19     execute "CREATE INDEX collections_full_text_search_idx ON collections USING gin(#{Collection.full_text_tsvector});"
20   end
21
22   def down
23     remove_index :collections, name: 'collections_search_index'
24     add_column :collections, :redundancy_confirmed_by_client_uuid, :string
25     RENAME.reverse.each do |oldname, newname|
26       rename_column :collections, newname, oldname
27     end
28     remove_index :collections, :name => 'collections_full_text_search_idx'
29     Collection.reset_column_information
30
31     execute "CREATE INDEX collections_full_text_search_idx ON collections USING gin(#{Collection.full_text_tsvector});"
32     add_index :collections, ["owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "portable_data_hash", "uuid", "name", "file_names", "redundancy_confirmed_by_client_uuid"], name: 'collections_search_index'
33   end
34 end