Это должно быть сделано в два этапа - первый создания индекса нужно в одной миграции файл и отбрасывая существующее в другом.
Первый файл:
class AddNewIndex < ActiveRecord::Migration
disable_ddl_transaction!
def change
add_index(
:users,
:email,
unique: false,
name: "index_non_unique_emails_on_users",
algorithm: :concurrently
)
end
end
Второй файл:
class DropOldListCIndexFromPushLogs < ActiveRecord::Migration
def change
remove_index(
:users,
name: <existing unique index name> # have a look in db/schema.rb
) if index_exists?(:users, name: "index_non_unique_emails_on_users")
end
end
Пожалуйста, посмотрите на Zero Downtime Migrations' readme, если вы новичок в безопасные миграции.