class AddIndicesForUser < ActiveRecord::Migration
  def up
    add_index :users, :email, unique: true
    add_index :users, :reset_password_token, unique: true
  end

  def down
    remove_index :users, :email, unique: true
    remove_index :users, :reset_password_token
  end
end

class AddIndicesForUser < ActiveRecord::Migration
  def try_to(&block)
    begin
      yield
    rescue => e
      puts e
    end
  end

  def up
    try_to { add_index :users, :email, unique: true }
    try_to { add_index :users, :reset_password_token, unique: true }
  end

  def down
    remove_index :users, :email, unique: true
    remove_index :users, :reset_password_token
  end
end

Allow all migrations to run in sequence
Allow all migrations to run in sequence

An earlier migration does actually create these indexes. However the
schema.rb at some point had got out of sync with the schema generated by
running migrations in order. I suspect that this migration was created
to fix a db schema created by loading a schema, rather than by running
all migrations from scratch.

This approach of swallowing the errors on creation of the index seemed
to be the most robust way of allowing all migrations to be run in order.
