On Jan 13, 2011, at 5:53 PM, Peter Booth wrote:

> After having a number of DB consistency issues I began adding constraints to 
> enforce foreign keys 
> and uniqueness of non-index columns checks. I ran a script like the following:
> 
> ALTER TABLE phones ADD CONSTRAINT unique_phones UNIQUE (number);
> ALTER TABLE emails ADD CONSTRAINT unique_emails UNIQUE (address);
> ALTER TABLE rates ADD CONSTRAINT foreign_business FOREIGN KEY (business_id) 
> REFERENCES businesses (id);
> ALTER TABLE phones ADD CONSTRAINT foreign_business FOREIGN KEY (business_id) 
> REFERENCES businesses (id);
> ALTER TABLE emails ADD CONSTRAINT foreign_business FOREIGN KEY (business_id) 
> REFERENCES businesses (id);
> ALTER TABLE locations ADD CONSTRAINT foreign_business FOREIGN KEY 
> (business_id) REFERENCES businesses (id);
> 
> Now I have a problem where whenever I run script/generate hobo_migration my 
> migration script automatically includes 
> lines to remove the uniqueness constraints, which I then have to manually 
> comment out.
> 
>  Is there a way to tell Hobo to ignore these indexes when creating a new 
> migration?
> 
> 
>   def self.up
>     add_column :providers, :photo_file_name, :string
>     add_column :providers, :photo_content_type, :string
>     add_column :providers, :photo_file_size, :integer
>     add_column :providers, :photo_updated_at, :datetime
>  #  remove_index :phones, :name => :unique_phones rescue 
> ActiveRecord::StatementInvalid
>  #  remove_index :emails, :name => :unique_emails rescue 
> ActiveRecord::StatementInvalid
>   end

Not the best solution, but adding

index :number, :unique => true, :name => 'unique_phones'

to your Phone model should inform Hobo what's going on. Long-term, it would be 
really nice to be able to declare those constraints in the model, but I don't 
think Rails provides a portable way to inspect constraints, nor if such a thing 
is even possible.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to