add additional database table connecting game matches to participating players

This commit is contained in:
2026-11-10 01:04:07 +03:00
parent 271daac935
commit 219448ccfb
10 changed files with 103 additions and 3 deletions
@@ -0,0 +1,23 @@
class CreateMatchPlayers < ActiveRecord::Migration[8.1]
def change
create_table :match_players do |t|
t.string :match_uuid, null: false
t.references :player, null: false, foreign_key: { to_table: :users }
end
add_foreign_key :match_players, :matches, column: :match_uuid, primary_key: :uuid
add_index :match_players, :match_uuid
add_index :match_players, [ :match_uuid, :player_id ], unique: true
reversible do |dir|
dir.up do
execute <<~SQL
INSERT INTO match_players (match_uuid, player_id)
SELECT uuid, player1_id FROM matches
UNION ALL
SELECT uuid, player2_id FROM matches
SQL
end
end
end
end
+11 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_11_03_000000) do
ActiveRecord::Schema[8.1].define(version: 2026_11_09_215241) do
create_table "active_storage_attachments", force: :cascade do |t|
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
@@ -39,6 +39,14 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_03_000000) do
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "match_players", force: :cascade do |t|
t.string "match_uuid", null: false
t.integer "player_id", null: false
t.index ["match_uuid", "player_id"], name: "index_match_players_on_match_uuid_and_player_id", unique: true
t.index ["match_uuid"], name: "index_match_players_on_match_uuid"
t.index ["player_id"], name: "index_match_players_on_player_id"
end
create_table "matches", force: :cascade do |t|
t.datetime "created_at", null: false
t.integer "duration_seconds"
@@ -81,6 +89,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_03_000000) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "match_players", "matches", column: "match_uuid", primary_key: "uuid"
add_foreign_key "match_players", "users", column: "player_id"
add_foreign_key "matches", "users", column: "player1_id"
add_foreign_key "matches", "users", column: "player2_id"
add_foreign_key "sessions", "users"