class MigrateCompetitionModuleContent < ActiveRecord::Migration[5.2]
  def change
    Competition.all.each do |competition|
      competition.informs.each do |inform|
        if inform.status == 1
          com_module = competition.competition_modules.find_by(module_type: "inform")
        elsif inform.status == 2
          com_module = competition.competition_modules.find_by(name: "参赛手册")
        end
        if com_module
          new_md = CompetitionModuleMdContent.create!(competition_module_id: com_module.id, content: inform.description, name: inform.name)
          Attachment.where(container_id: inform.id, container_type: "Inform").update_all(container_id: new_md.id, container_type: "CompetitionModuleMdContent")
        end
      end
    end
  end
end
