class ModifyContentsForOldMessageDetails < ActiveRecord::Migration[5.2]
  def change
    messages = Message.where(subject: "新课导语").where.not(parent_id: 0).where("created_on < '2019-08-23 02:00:00'")
    messages.find_each do |m|
      m.update_column(:is_md, true)
      message_detail = m.message_detail
      if message_detail
        content = OldMessageDetail.find_by_id(message_detail.id)&.content
        message_detail.update_column(:content, content)
      end
    end
  end
end
