Merge branch '19993-groupby-forupdate'
[arvados.git] / services / api / db / migrate / 20180919001158_recreate_collection_unique_name_index.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class RecreateCollectionUniqueNameIndex < ActiveRecord::Migration[4.2]
6   def up
7     Collection.transaction do
8       remove_index(:collections,
9                    name: 'index_collections_on_owner_uuid_and_name')
10       add_index(:collections, [:owner_uuid, :name],
11                 unique: true,
12                 where: 'is_trashed = false AND current_version_uuid = uuid',
13                 name: 'index_collections_on_owner_uuid_and_name')
14     end
15   end
16
17   def down
18     Collection.transaction do
19       remove_index(:collections,
20                    name: 'index_collections_on_owner_uuid_and_name')
21       add_index(:collections, [:owner_uuid, :name],
22                 unique: true,
23                 where: 'is_trashed = false',
24                 name: 'index_collections_on_owner_uuid_and_name')
25     end
26   end
27 end