19 lines
441 B
Ruby
19 lines
441 B
Ruby
class AddContactIdToEmails < ActiveRecord::Migration
|
|
def self.up
|
|
change_table :emails do |t|
|
|
t.references :contact
|
|
end
|
|
# add the foreign key
|
|
execute <<-SQL
|
|
ALTER TABLE emails
|
|
ADD CONSTRAINT fk_emails_contacts
|
|
FOREIGN KEY (contact_id)
|
|
REFERENCES contacts(id)
|
|
SQL
|
|
end
|
|
|
|
def self.down
|
|
execute "ALTER TABLE emails DROP FOREIGN KEY fk_emails_contacts"
|
|
remove_column :emails, :contact_id
|
|
end
|
|
end
|