I'm using UUID as primary key in my tables, created in this way:
Migration:
class CreateAccounts < ActiveRecord::Migration
def change
create_table :accounts, :id => false do |t|
t.uuid :uuid, :null => false
t.timestamps
end
execute "ALTER TABLE accounts ADD PRIMARY KEY (uuid);"
add_index :accounts, :uuid, :unique => true
end
end
Model:
class Account < ActiveRecord::Base
primary_key = :uuid
base.default_value_for(:uuid, :allows_nil => false) { UUIDTools::UUID.random_create.to_s }
end
But I now see that I have double indexes on the primary key UUID column:

(1) I guess this comes from ADD PRIMARY KEY which creates the "XXX_pkey" index, and I can safely remove add_index :accounts, :uuid, :unique => true in this migration and from the running database?
(2) I can see that only the manually added index is used, and not the automatically added. Is this by random?
(3) Which of these indexes should be removed and what is the best way to do that in production through Rails' migrations?