I am creating a database that tracks replays for a game. Each replay has a different game mode that is either team-based gameplay or individual-based gameplay. Depending on the game mode, I want to record the winning team or the winning individual.
I have the following MySQL table that tracks rounds in the replay and the associated winner:
CREATE TABLE replay_rounds (
replay_id INT UNSIGNED NOT NULL,
round SMALLINT UNSIGNED NOT NULL,
winning_player_id INT UNSIGNED,
winning_team_id TINYINT UNSIGNED,
FOREIGN KEY (replay_id) REFERENCES replays(id),
FOREIGN KEY (replay_id, winning_player_id) REFERENCES replay_players(replay_id, player_id),
FOREIGN KEY (winning_team_id) REFERENCES teams(id),
PRIMARY KEY (replay_id, round))
CHARACTER SET=utf8
COLLATE=utf8_general_ci
ENGINE=InnoDB;
Using what I have now, if the game mode is team-based then I will set the winning_team_id for each round and set the winning_player_id to null
. Likewise, if the game mode is individual-based, I will set the winning_team_id to null
.
Performance-wise and in terms of best practice, is it all right to leave it like this? Is there a compelling reason to split this into a separate table for each game mode (even if there's only two modes)? How about a hypothetical situation where game modes are constantly being added -- would this be best resolved by creating a table for every new game mode?