Unique Marketing, Guaranteed Results.

Foreign Key Migrations Plugin

April 2nd, 2009 by Chuck Wood

I worked on a plugin yesterday that would include all of our migration helpers. You can find it on github. Currently, it only does foreign keys work, but eventually, I’d like to have it add unique indexes on columns defined with a :unique => true attribute in the ActiveRecord migration. But for right now, here’s how to use it:

Adding a foreign key that references the id column in another table:

# The column 'id' is assumed in the referenced table.
add_foreign_key :table1, :table2_ref, :table2

Adding a foreign key that references the name column in another table:

add_foreign_key :table1, :table2_name, :table2, :name

Removing a foreign key with a custom name for the SQL constraint:

drop_foreign_key :table1, "table1_ref_to_table2"

Removing a foreign key with no custom name for the SQL constraint:

drop_foreign_key :table1, :table2_ref
  • Facebook
  • Google Bookmarks
  • email
  • NewsVine
  • Slashdot
  • Technorati
  • Yahoo! Buzz
  • BlinkList
  • Print
  • Propeller
Filed under: Programming — Tags: , , , , — Chuck Wood @ 9:33 am on April 2, 2009

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment


Copyright © 2005-2010 PMA Media Group. All Rights Reserved . Online Degrees | Train for a Better Career | My Colleges and Careers Site Map