X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/399366e7e32906099d22acddf44ad0cd2ca9a1e1..b16f84a8c5562cd5c3939e8c445dc86df2be2d4b:/services/api/db/migrate/20150216193428_collection_name_owner_unique_only_non_expired.rb?ds=sidebyside diff --git a/services/api/db/migrate/20150216193428_collection_name_owner_unique_only_non_expired.rb b/services/api/db/migrate/20150216193428_collection_name_owner_unique_only_non_expired.rb index 1124d5efb3..6e581883c5 100644 --- a/services/api/db/migrate/20150216193428_collection_name_owner_unique_only_non_expired.rb +++ b/services/api/db/migrate/20150216193428_collection_name_owner_unique_only_non_expired.rb @@ -1,6 +1,18 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class CollectionNameOwnerUniqueOnlyNonExpired < ActiveRecord::Migration + def find_index + indexes = ActiveRecord::Base.connection.indexes('collections') + name_owner_index = indexes.select do |index| + index.name == 'collection_owner_uuid_name_unique' + end + name_owner_index + end + def up - remove_index :collections, :name => 'collection_owner_uuid_name_unique' + remove_index :collections, :name => 'collection_owner_uuid_name_unique' if !find_index.empty? add_index(:collections, [:owner_uuid, :name], unique: true, where: 'expires_at is null', name: 'collection_owner_uuid_name_unique') @@ -8,7 +20,7 @@ class CollectionNameOwnerUniqueOnlyNonExpired < ActiveRecord::Migration def down # it failed during up. is it going to pass now? should we do nothing? - remove_index :collections, :name => 'collection_owner_uuid_name_unique' + remove_index :collections, :name => 'collection_owner_uuid_name_unique' if !find_index.empty? add_index(:collections, [:owner_uuid, :name], unique: true, name: 'collection_owner_uuid_name_unique') end