On 15.02.2011, at 01:37, craayzie wrote:

> 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.

The uniqueness of a field in rails is a programatic constrain in ruby, not a 
constrain on the database layer.
The vhost.yml file takes care of this and evaluates this.

https://github.com/saturnflyer/radiant-vhost-extension/blob/master/lib/vhost/site_scoped_model_extensions.rb#L12

> 
> 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?

yes:

There is some code in the rake radiant:extensions:vhost:apply_site_scoping 
which alters special index
behaviour. At least for snippets it should just work

https://github.com/saturnflyer/radiant-vhost-extension/blob/master/lib/tasks/add_site_columns.rb#L45

> 
> 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 <flesh...@gmail.com> 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)
>> ============================

--
DI Edmund Haselwanter, edm...@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | http://facebook.com/iTeh.solutions | 
http://at.linkedin.com/in/haselwanteredmund 





Reply via email to