competition personal enroll data transfer

dev_bj
p31729568 5 years ago
parent 90ff785469
commit 590bdde692

@ -0,0 +1,26 @@
class TransferCompetitionPersonalEnrollData < ActiveRecord::Migration
CODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
def change
gcc_task = Competition.find_by_identifier('gcc-task-2019')
transfer_personal_enroll_data(gcc_task)
gcc_annotation = Competition.find_by_identifier('gcc-annotation-2019')
transfer_personal_enroll_data(gcc_annotation)
end
def transfer_personal_enroll_data(competition)
return if competition.blank?
competition.competition_teams.where('invite_code IS NULL OR invite_code = ""').each do |team|
team.update_attributes!(invite_code: generate_team_code, name: "#{team.name}战队")
end
end
def generate_team_code
code = CODES.sample(6).join
while CompetitionTeam.exists?(invite_code: code)
code = CODES.sample(6).join
end
code
end
end
Loading…
Cancel
Save