summaryrefslogtreecommitdiff
path: root/db/migrate/20150420210728_add_ptype_to_participants.rb
blob: 679321a82676dc18ea34165d5326e69480efd395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class AddPtypeToParticipants < ActiveRecord::Migration
  def self.up
    add_column :participants, :ptype, :string
    assign_participant_type
  end

  def self.down
    remove_column :participants, :ptype
  end

private

  def self.assign_participant_type
    Participant.all.each do |p|
      case
        when p.mainparticipant? then  p.ptype= Participant::TYPE[:main]
        when p.subparticipant? then  p.ptype= Participant::TYPE[:sub]
        when p.anonymousparticipant? then  p.ptype= Participant::TYPE[:anonym]
      end
      p.save!
    end
  end
end