8784: Fix test for latest firefox.
[arvados.git] / services / api / db / migrate / 20150216193428_collection_name_owner_unique_only_non_expired.rb
1 class CollectionNameOwnerUniqueOnlyNonExpired < ActiveRecord::Migration
2   def find_index
3     indexes = ActiveRecord::Base.connection.indexes('collections')
4     name_owner_index = indexes.select do |index|
5       index.name == 'collection_owner_uuid_name_unique'
6     end
7     name_owner_index
8   end
9
10   def up
11     remove_index :collections, :name => 'collection_owner_uuid_name_unique' if !find_index.empty?
12     add_index(:collections, [:owner_uuid, :name], unique: true,
13               where: 'expires_at is null',
14               name: 'collection_owner_uuid_name_unique')
15   end
16
17   def down
18     # it failed during up. is it going to pass now? should we do nothing?
19     remove_index :collections, :name => 'collection_owner_uuid_name_unique' if !find_index.empty?
20     add_index(:collections, [:owner_uuid, :name], unique: true,
21               name: 'collection_owner_uuid_name_unique')
22   end
23 end