Agile Web Development

Build it. Launch it. Love it.

Foreign Key Schema Dumper

This plugin adds support for Foreign Key Constraints in schema dumper. After adding this plugin, do a rake dbschemadump and you'll see statements for adding constraints in your schema.rb. (Works with MySQL, and PostgreSQL)

You can use this plugin for your migrations as well. The syntax for adding FK constraints is:

add_foreign_key_constraint table, foreign_key, reference_table, reference_column, 
:name => optional_constraint_name, 
:on_update => optional_on_update_action, 
:on_delete => optional_on_delete_action

The actions are symbols. One of: :cascade, :set_null, or :restrict If you don't want any action, "no action", then just omit these optional parameters.

For removing:

You have two options:

  1. :name => the name of the foreign key constraint
  2. :foreignkey => the name of the column for which the foreign key was created (only if the default constraintname was used)

*Note*: This is for inside ActiveRecord::Schema not inside migrations. You can use removeforeignkey_constraint but it takes just the table name and constraint name

Vitals

Home http://wiki.rubyonrails.org/rails/pages/Foreign+Key+Schema+Dumper+Plugin
License
Tags Tag_red
Rating (2 votes)
Created 25 May 2006

Comments

Add a comment