From 590bdde692e356710ae05b356e12b72c48fce4ca Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 1 Jul 2019 10:39:12 +0800 Subject: [PATCH] competition personal enroll data transfer --- ...ansfer_competition_personal_enroll_data.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 db/migrate/20190701022644_transfer_competition_personal_enroll_data.rb diff --git a/db/migrate/20190701022644_transfer_competition_personal_enroll_data.rb b/db/migrate/20190701022644_transfer_competition_personal_enroll_data.rb new file mode 100644 index 00000000..4c59ad14 --- /dev/null +++ b/db/migrate/20190701022644_transfer_competition_personal_enroll_data.rb @@ -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