This gem implements "add_foreign_key" and "remove_foreign_key" for PostgreSQLAdapter.
- activerecord
- postgres
$ sudo gem sources -a http://gems.github.com (you only have to do this once)
$ sudo gem install rafaelp-postgresql_migrations
require 'postgresql_migrations'
class UserBelongsToAccount < ActiveRecord::Migration
def self.up
add_foreign_key :users, :account_id, :accounts, :id
end
def self.down
remove_foreign_key :users, :account_id
end
end
require 'postgresql_migrations'
class UserBelongsToAccount < ActiveRecord::Migration
def self.up
add_foreign_key :users, :account_id, :accounts, :id, :match => 'simple', :on_delete => 'restrict', :on_update => 'cascade'
end
def self.down
remove_foreign_key :users, :account_id
end
end
Postgresql Migrations is released under the MIT License.
Working at Myfreecomm
Blog: http://rafael.adm.br
Podcast: http://rafael.adm.br/voltandopracasa
Github: http://github.com/rafaelp
Twitter: http://twitter.com/rafaelp