class MigrateCompetitionModuleType < ActiveRecord::Migration[5.2]
  def change
    add_column :competition_modules, :module_type, :string

    Competition.all.each do |competition|
      competition.competition_modules.each do |com_module|
        mod_type = ""
        case com_module.name
        when '首页'
          mod_type = "home"
        when '报名'
          mod_type = "enroll"
        when '通知公告'
          mod_type = "inform"
        when '参赛手册'
          mod_type = "manual"
        when '排行榜'
          mod_type = "chart"
        when '资料下载'
          mod_type = "resource"
        else
          mod_type = "md"
        end
        com_module.update_attributes!(module_type: mod_type)
      end
    end
  end
end
