How can I change an index defined on a table?

indexing, ruby, ruby-on-rails-3

Solution

Different index types are typically implemented in very different ways in the database you are using. A primary index is very different from any secondary index. And unique indexes are typically different from search indexes to facilitate their primary use case: to quickly determine if a value is already present in a column vs. allowing efficient searches.

As such, (depending on your DBMS) you can't change an existing index. You safest bet in any case is to drop the index and create a new one. This can be done during live operations. There is no need to shutdown neither the database nor your rails app.

Problem

I have an index defined like ``` add_index :users, :email, :unique => true ``` Is there any way to change this index to drop the UNIQUE constraint, something like 'change_index'? Or is it the only way to drop the index and add it again without the UNIQUE constraint?

Original source