diff --git a/db/migrate/4_add_unique_index_to_friendships.rb b/db/migrate/4_add_unique_index_to_friendships.rb index 7341340..a04279d 100644 --- a/db/migrate/4_add_unique_index_to_friendships.rb +++ b/db/migrate/4_add_unique_index_to_friendships.rb @@ -8,7 +8,9 @@ class AddUniqueIndexToFriendships < ActiveRecord::Migration; end disable_ddl_transaction! def self.up - add_index :friendships, [:friendable_id, :friend_id], unique: true, algorithm: :concurrently unless index_exists? (:friendable_id, :friend_id) + return if index_exists?(:friendships, [:friendable_id, :friend_id]) + + add_index :friendships, [:friendable_id, :friend_id], unique: true, algorithm: :concurrently end def self.down