Chatwoot/db/migrate/20200206180408_add_contact_to_message.rb

13 lines
338 B
Ruby
Raw Normal View History

class AddContactToMessage < ActiveRecord::Migration[6.0]
def change
add_reference(:messages, :contact, foreign_key: true, index: true)
::Message.all.each do |message|
conversation = message.conversation
next if conversation.contact.nil?
message.update!(contact_id: conversation.contact.id)
end
end
end