#!/usr/bin/env ruby
require File.expand_path('../../../config/environment', __FILE__)
ForeignKey.disabled

Swars::Xmode.destroy_all
Swars::Xmode.setup

Swars::Battle.destroy_all
Swars::User.destroy_all

user1 = Swars::User.create!
user2 = Swars::User.create!

2.times do
  Swars::Battle.create! do |e|
    e.memberships.build(user: user1)
    e.memberships.build(user: user2)
  end
  Swars::Battle.create! do |e|
    e.memberships.build(user: user2)
    e.memberships.build(user: user1)
  end
end

Swars::Battle.update_all(:xmode_id => Swars::Xmode.fetch("指導").id)

tp Swars::Battle
tp Swars::User
tp Swars::Membership

# >>    (0.3ms)  select 1
# >> |---|
# >> | 1 |
# >> |---|
# >> | 1 |
# >> |---|
# >>   Swars::Xmode Load (0.3ms)  SELECT `swars_xmodes`.* FROM `swars_xmodes` WHERE `swars_xmodes`.`key` = '指導' LIMIT 1
# >>   ↳ app/models/concerns/memory_record_bind.rb:53:in `fetch'
# >>   Swars::Battle Update All (0.8ms)  UPDATE `swars_battles` SET `swars_battles`.`xmode_id` = 22
# >>   Swars::Battle Load (0.4ms)  SELECT `swars_battles`.* FROM `swars_battles`
# >> |----+---------+---------------------------+----------+--------------------------------------------------------------------------------------------+-----------+-------------+----------+-----------+---------------------------+------------+--------------------------------------------------------------------------------------------------------------+----------------------------------+------------+---------------+---------------+------------+---------------------------+---------------------------+-----------+------------------+-----------------+--------------------+---------------+----------------|
# >> | id | key     | battled_at                | rule_key | csa_seq                                                                                    | final_key | win_user_id | turn_max | meta_info | accessed_at               | preset_key | sfen_body                                                                                                    | sfen_hash                        | start_turn | critical_turn | outbreak_turn | image_turn | created_at                | updated_at                | xmode_id | defense_tag_list | attack_tag_list | technique_tag_list | note_tag_list | other_tag_list |
# >> |----+---------+---------------------------+----------+--------------------------------------------------------------------------------------------+-----------+-------------+----------+-----------+---------------------------+------------+--------------------------------------------------------------------------------------------------------------+----------------------------------+------------+---------------+---------------+------------+---------------------------+---------------------------+-----------+------------------+-----------------+--------------------+---------------+----------------|
# >> | 55 | alice-bob-20000101_000000 | 2022-04-16 10:20:14 +0900 | ten_min  | [["+7968GI", 599], ["-8232HI", 597], ["+5756FU", 594], ["-3334FU", 590], ["+6857GI", 592]] | TORYO     |          49 |        5 | {}        | 2022-04-16 10:20:14 +0900 | 平手       | position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves 7i6h 8b3b 5g5f 3c3d 6h5g | 7b7e2206a9d4cdf21d06bc390228ced8 |            |               |               |            | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |        22 |                  |                 |                    |               |                |
# >> | 56 | battle2 | 2022-04-16 10:20:15 +0900 | ten_min  | [["+7968GI", 599], ["-8232HI", 597], ["+5756FU", 594], ["-3334FU", 590], ["+6857GI", 592]] | TORYO     |          50 |        5 | {}        | 2022-04-16 10:20:15 +0900 | 平手       | position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves 7i6h 8b3b 5g5f 3c3d 6h5g | 7b7e2206a9d4cdf21d06bc390228ced8 |            |               |               |            | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |        22 |                  |                 |                    |               |                |
# >> | 57 | battle3 | 2022-04-16 10:20:15 +0900 | ten_min  | [["+7968GI", 599], ["-8232HI", 597], ["+5756FU", 594], ["-3334FU", 590], ["+6857GI", 592]] | TORYO     |          49 |        5 | {}        | 2022-04-16 10:20:15 +0900 | 平手       | position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves 7i6h 8b3b 5g5f 3c3d 6h5g | 7b7e2206a9d4cdf21d06bc390228ced8 |            |               |               |            | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |        22 |                  |                 |                    |               |                |
# >> | 58 | battle4 | 2022-04-16 10:20:15 +0900 | ten_min  | [["+7968GI", 599], ["-8232HI", 597], ["+5756FU", 594], ["-3334FU", 590], ["+6857GI", 592]] | TORYO     |          50 |        5 | {}        | 2022-04-16 10:20:15 +0900 | 平手       | position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves 7i6h 8b3b 5g5f 3c3d 6h5g | 7b7e2206a9d4cdf21d06bc390228ced8 |            |               |               |            | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |        22 |                  |                 |                    |               |                |
# >> |----+---------+---------------------------+----------+--------------------------------------------------------------------------------------------+-----------+-------------+----------+-----------+---------------------------+------------+--------------------------------------------------------------------------------------------------------------+----------------------------------+------------+---------------+---------------+------------+---------------------------+---------------------------+-----------+------------------+-----------------+--------------------+---------------+----------------|
# >>   Swars::User Load (0.4ms)  SELECT `swars_users`.* FROM `swars_users`
# >> |----+----------+----------+-------------------+-------------------+---------------------------+---------------------------|
# >> | id | user_key | grade_id | last_reception_at | search_logs_count | created_at                | updated_at                |
# >> |----+----------+----------+-------------------+-------------------+---------------------------+---------------------------|
# >> | 49 | user1    |       40 |                   |                 0 | 2022-04-16 10:20:14 +0900 | 2022-04-16 10:20:15 +0900 |
# >> | 50 | user2    |       40 |                   |                 0 | 2022-04-16 10:20:14 +0900 | 2022-04-16 10:20:15 +0900 |
# >> |----+----------+----------+-------------------+-------------------+---------------------------+---------------------------|
# >>   Swars::Membership Load (0.3ms)  SELECT `swars_memberships`.* FROM `swars_memberships`
# >> |-----+-----------+---------+------------+----------+-----------+--------------+----------+------------+---------------------------+---------------------------+---------------+---------------+----------------+------------+-----------+---------------+--------------+------------------+-----------------+--------------------+---------------+----------------|
# >> | id  | battle_id | user_id | op_user_id | grade_id | judge_key | location_key | position | grade_diff | created_at                | updated_at                | think_all_avg | think_end_avg | two_serial_max | think_last | think_max | obt_think_avg | ai_drop_total | defense_tag_list | attack_tag_list | technique_tag_list | note_tag_list | other_tag_list |
# >> |-----+-----------+---------+------------+----------+-----------+--------------+----------+------------+---------------------------+---------------------------+---------------+---------------+----------------+------------+-----------+---------------+--------------+------------------+-----------------+--------------------+---------------+----------------|
# >> | 109 |        55 |      49 |         50 |       40 | win       | black        |        0 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             2 |             2 |              1 |          2 |         5 |               |              |                  |                 |                    |               |                |
# >> | 110 |        55 |      50 |         49 |       40 | lose      | white        |        1 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             5 |             5 |                |          7 |         7 |               |              |                  |                 |                    |               |                |
# >> | 111 |        56 |      50 |         49 |       40 | win       | black        |        0 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             2 |             2 |              1 |          2 |         5 |               |              |                  |                 |                    |               |                |
# >> | 112 |        56 |      49 |         50 |       40 | lose      | white        |        1 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             5 |             5 |                |          7 |         7 |               |              |                  |                 |                    |               |                |
# >> | 113 |        57 |      49 |         50 |       40 | win       | black        |        0 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             2 |             2 |              1 |          2 |         5 |               |              |                  |                 |                    |               |                |
# >> | 114 |        57 |      50 |         49 |       40 | lose      | white        |        1 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             5 |             5 |                |          7 |         7 |               |              |                  |                 |                    |               |                |
# >> | 115 |        58 |      50 |         49 |       40 | win       | black        |        0 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             2 |             2 |              1 |          2 |         5 |               |              |                  |                 |                    |               |                |
# >> | 116 |        58 |      49 |         50 |       40 | lose      | white        |        1 |          0 | 2022-04-16 10:20:15 +0900 | 2022-04-16 10:20:15 +0900 |             5 |             5 |                |          7 |         7 |               |              |                  |                 |                    |               |                |
# >> |-----+-----------+---------+------------+----------+-----------+--------------+----------+------------+---------------------------+---------------------------+---------------+---------------+----------------+------------+-----------+---------------+--------------+------------------+-----------------+--------------------+---------------+----------------|
