diff --git a/db/migrate/20200311092049_add_index_user_id_challenge_id_for_games.rb b/db/migrate/20200311092049_add_index_user_id_challenge_id_for_games.rb new file mode 100644 index 000000000..c9fab49d4 --- /dev/null +++ b/db/migrate/20200311092049_add_index_user_id_challenge_id_for_games.rb @@ -0,0 +1,9 @@ +class AddIndexUserIdChallengeIdForGames < ActiveRecord::Migration[5.2] + def change + delete_games = Game.where.not(myshixun_id: Myshixun.all).reorder(nil) + puts "delete_games: #{delete_games.pluck(:id)}" + delete_games.destroy_all + + add_index :games, [:user_id, :challenge_id], unique: true + end +end