Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Philword's avatar

Database Design for Tournament

Hey guys,

I'm design DB for tournament website.

What I eventually need: Every match has 3 maps. Every map has own score for each team (score_left_team -Map_name - score right team ). And every match has general score (left_team_score - right_team_score) Perfect example: https://overwatchleague.com/en-us/match/10223

Please help me to improve my design below:

Team::
 id
 name

Player::
 id
 team_id
 name

Map::
 id
 name
 photo

Match::
 id
 date
 stage_name
 group_name
 map_id
 left_team_id
 right_team_id
 score_left
 score_right
 winner
 status (scheduled, live, completed)
0 likes
5 replies
mcangueiro's avatar

I think you also need to keep track of the score of each map, right? So, you could add a column for that in the Map table. Also, you have a map_id in the Match table, but what if the match has 2 or more maps played? I think you need to change that so the Map table has a match_id and as such a match can have multiple maps.

1 like
Philword's avatar

@mcangueiro Thank you! Think it will work?

Team:: (hasMany Players)
 id
 name

Player:: (belongs to Team)
 id
 team_id
 name

Map:: (belongs to Match-Map)
 id
 name
 photo

Match_Map:: (hasMany Maps \ belongs to Match)
 id
 map_id
 match_id
 score_left
 score_right

Match:: (hasMany Match-Maps )
 id
 date
 stage_name
 group_name
 left_team_id
 right_team_id
 score_left
 score_right
 winner
 status (scheduled, live, completed)
biishmar's avatar

@PHILWORD Use pivot table for Match and map for different maps then use pivot for left team and right team dont save it like array or json.. it will collapse the eloquent relationship.. divide the winner according to map winner and match winner for later reference.. you can also add score in match left and right team pivot table so can save individual score....

Team:: 
 id
 name

Player:: 
 id
 team_id
 name

Map:: 
 id
 name
 photo

Match:: 
 id
 date
 stage_name
 group_name
 match_winner
 status (scheduled, live, completed)

MapMatch::
 id
 map_id
 match_id
 score_left
 score_right
 map_winner

MatchLeftTeam::
id
player_id
match_id
score

MatchRightTeam::
id
player_id
match_id
score

Hope this helps

1 like
Philword's avatar

@biishmar Thanks for your tip!

I have never use pivot table, guess need to figure out how to handle it) Any tips from where to start? Just don't get the logic how to build relationships

biishmar's avatar

@Philword

Team -> hasMany -> Player
Player ->belongsTo -> Team
Match -> belongToMany -> Map (Pivot table MatchMap)
Match -> belongToMany -> Player (Pivot table MatchRightTeam)
Match -> belongToMany -> Player (Pivot table MatchLeftTeam)

These are your relationship check the laravel documentation to see how to create these relationship by coding...

1 like

Please or to participate in this conversation.