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