parent
78abb9a4fc
commit
80da247b8d
@ -0,0 +1,27 @@
|
||||
class AddTeamMemberForCompetitionTeams < ActiveRecord::Migration
|
||||
def up
|
||||
def generate_team_code
|
||||
code = %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).sample(6).join
|
||||
return generate_team_code if CompetitionTeam.where(invite_code: code).present?
|
||||
code
|
||||
end
|
||||
|
||||
user_ids = User.where(is_test: true).pluck(:id)
|
||||
while(user_ids.length > 0)
|
||||
users = user_ids.pop(rand(3..5))
|
||||
invite_code = generate_team_code
|
||||
puts("#{invite_code}");
|
||||
new_team = CompetitionTeam.create!(:competition_id => 6, :name => "daiao#{users[0]}",
|
||||
:invite_code => invite_code, :user_id => users[0])
|
||||
users.each_with_index do |u, index|
|
||||
role = index == 0 ? 1 : 0
|
||||
is_teacher = index == 0 ? 1 : 0
|
||||
new_team.team_members.create!(user_id: u, role: role, competition_id: 6,
|
||||
is_teacher: is_teacher)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in new issue