contactorama/db/migrate/20110517220955_add_contact_id_to_phones.rb

19 lines
441 B
Ruby

class AddContactIdToPhones < ActiveRecord::Migration
def self.up
change_table :phones do |t|
t.references :contact
end
# add the foreign key
execute <<-SQL
ALTER TABLE phones
ADD CONSTRAINT fk_phones_contacts
FOREIGN KEY (contact_id)
REFERENCES contacts(id)
SQL
end
def self.down
execute "ALTER TABLE phones DROP FOREIGN KEY fk_phones_contacts"
remove_column :phones, :contact_id
end
end