19 lines
441 B
Ruby
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
|