On Thursday, March 26, 2015 at 10:34:07 AM UTC-7, Andrew Burleson wrote:
>
> Are there any gotchas associated with renaming a foreign key column in 
> Sequel?
>
> ie: let's say I have a model like:
>
> class Foo < Sequel::Model
>   many_to_one :zap
> end
>
>
> This would have been created like
> create_table :foos do
>   foreign_key :zap_id, :zaps
> end
>
>
> If I later need to change `Zap` to `Zip`, it seems to work if I do a 
> migration like:
> rename_table :zaps, :zips
> alter_table :foos do
>   rename_column :zap_id, :zip_id
> end
>
> But is the foreign key constraint also renamed, or is there more that 
> needs to be done? Any known gotchas about renaming a table and the foreign 
> key columns that point to it?
>

I think most databases handle column renaming in foreign key constraints 
automatically (i.e. the foreign key constraint uses references internally, 
not names).  You shouldn't need to rename the constraint itself, though 
some databases support that (ALTER TABLE RENAME CONSTRAINT on PostgreSQL 
9.2+).  However, Sequel doesn't have DSL support for renaming constraints, 
you'd have to issue database-specific SQL for that.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to