Below is the migration that finally did the trick! There wasn't really
a need to have an index on the name attribute anyways since it'll
always require the site_id.
I'm still interested in Haselwanter's note about how the config/
vhost.yml file alone should have taken care of this. Am I missing
something obvious here?
class CleanUpSnippetConstraints < ActiveRecord::Migration
def self.up
remove_index :snippets, :name => "name"
end
def self.down
add_index "snippets", ["name"], :name => "name", :unique => true
end
end
On Feb 14, 2:02 pm, craayzie <[email protected]> wrote:
> The migration to remove the unique constraint works great (below) but
> when I try to roll it back I get the following from sqlite:
>
> $ rake db:rollback
> (in /Users/username/Sites/heroku)
> == CleanUpSnippetConstraints1: reverting
> =====================================
> -- remove_index(:snippets, {:name=>"index_snippets_on_name"})
> -> 0.0010s
> -- add_index("snippets", ["name"], {:unique=>true, :name=>"name"})
> rake aborted!
> An error has occurred, this and all later migrations canceled:
>
> SQLite3::ConstraintException: indexed columns are not unique: CREATE
> UNIQUE INDEX "name" ON "snippets" ("name")
>
> $ cat db/migrate/20091003095746_clean_up_snippet_constraints1.rb
> class CleanUpSnippetConstraints1 < ActiveRecord::Migration
> def self.up
> remove_index :snippets, :name => "name"
> add_index :snippets, ["name"], :name =>
> "index_snippets_on_name", :unique => false
> end
>
> def self.down
> remove_index :snippets, :name => "index_snippets_on_name"
> add_index "snippets", ["name"], :name => "name", :unique => true
> end
> end
>
> $ rake db:migrate
> (in /Users/username/Sites/heroku)
> == CleanUpSnippetConstraints1: migrating
> =====================================
> -- remove_index(:snippets, {:name=>"name"})
> -> 0.0004s
> -- add_index(:snippets, ["name"],
> {:unique=>false, :name=>"index_snippets_on_name"})
> -> 0.0753s
> == CleanUpSnippetConstraints1: migrated (0.0760s)
> ============================