You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/db/migrate/20191112100418_migrate_gcc_...

26 lines
1.1 KiB

class MigrateGccProjectTeam < ActiveRecord::Migration[5.2]
def change
competition = Competition.find_by(id: 8)
if competition
competition.competition_teams.destroy_all
all_login = [['mu2pwryse', 'pljq3f9xp', 'pfx7gfmiz'], ['p9rs7xtfl', 'prx72s8uc', 'plezci23p', 'pjysrikw7'], ['m40352189', 'p05394287'],
['m9ozhx83t', 'p05296348'], ['p35490268', 'p48921607', 'p24019738'], ['p29165708', 'm43960821']]
all_login.each do |user_login|
5 years ago
leader = User.find_by(login: user_login.first)
next if leader.blank?
team = CompetitionTeam.create!(name: "#{leader.real_name}", user_id: leader.id, competition_id: 8)
team.generate_invite_code
team.save!
team.team_members.create!(user_id: leader.id, competition_id: competition.id, role: 1, is_teacher: 0)
user_login.each_with_index do |user_login, index|
if index > 0
user = User.find_by(login: user_login)
team.team_members.create!(user_id: user.id, competition_id: competition.id, role: 2, is_teacher: 0)
end
end
end
end
end
end