Skip to content

Commit 376ed80

Browse files
Merge pull request #29 from aureateAnatidae/SQL-diagram
docs: Add season table design to database design documents
2 parents 363847d + a266b8b commit 376ed80

4 files changed

Lines changed: 74 additions & 18 deletions

File tree

apps/backend/src/v1/match/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ app.get(
1515
description: "Successful response",
1616
content: {
1717
"application/json": {
18-
schema: resolver(z.object({ sets: z.array(MatchReport) })),
18+
schema: resolver(z.object({ matches: z.array(MatchReport) })),
1919
},
2020
},
2121
},
@@ -39,7 +39,7 @@ app.post(
3939
description: "Successful response",
4040
content: {
4141
"application/json": {
42-
schema: resolver(z.object({ set_id: z.int() })),
42+
schema: resolver(z.object({ match_id: z.int() })),
4343
},
4444
},
4545
},

apps/docsite/docs/Internal/concepts.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@ title: Concepts and Vocabulary
44

55
# Disambiguation
66

7-
## Match/Set
8-
When we refer to the games played between players, which are reported to Grindcord, we use the term "match" over "set". Despite "set" being more common to refer to a past game, it shadows the term "set", which is a reserved word in programming (the data structure).
7+
## Use the word `Match` over `Set` to refer to recorded games
8+
When we refer to the games played between players, which are reported to Grindcord, we use the term "match" over "set".
9+
10+
Despite "set" being more common to refer to a past game, it already has a meaning in programming (the data structure) and may cause confusion. Using the word `Set` or `set` in code may also shadow the built-in `Set()` object in code.
11+
12+
## GuildMember/User
13+
Grindcord is built for communities on Discord. Every user of Grindcord must also be a member of a guild (a Discord server) which has Grindcord installed.
14+
15+
A user of Grindcord is uniquely identied by their `id` (that we disambiguate as `user_id`), and their participation in a guild with a `guild_id`. So, a [`GuildMember`](https://discord.com/developers/docs/resources/guild#guild-member-object) is an object from the Discord API which represents a [`user`](https://discord.com/developers/docs/resources/user#user-object) and their participation in that guild.

apps/docsite/docs/Internal/database.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ Matches are reported to the backend. These reports contain the data:
1313
- Match count (3-0)
1414
- The fighters used by each respective user
1515

16-
##### External Dependencies
16+
# External Dependencies
1717

18-
A user of Grindcord SHOULD NOT be stored explicitly in our database. A [`GuildMember`](https://discord.com/developers/docs/resources/guild#get-guild-member) is an external dependency provided by Discord. A [`GuildMember`](https://discord.com/developers/docs/resources/guild#get-guild-member)'s `user_id` on the [`user`](https://discord.com/developers/docs/resources/user#user-object) field SHOULD be considered a primary key for our purposes.
18+
A user of Grindcord SHOULD NOT be stored explicitly in our database. A [`GuildMember`](https://discord.com/developers/docs/resources/guild#guild-member-object) is an external dependency provided by Discord. A [`GuildMember`](https://discord.com/developers/docs/resources/guild#guild-member-object)'s `user_id` on the [`user`](https://discord.com/developers/docs/resources/user#user-object) field SHOULD be considered a primary key for our purposes.
1919

20-
A guild SHOULD NOT be stored explicitly in our database. A [`Guild`](https://discord.com/developers/docs/resources/guild#get-guild) is an external dependency provided by Discord. A `Guild`'s `guild_id` SHOULD be considered a primary key for our purposes.
20+
A guild SHOULD NOT be stored explicitly in our database. A [`Guild`](https://discord.com/developers/docs/resources/guild#guild-object) is an external dependency provided by Discord. A `Guild`'s `guild_id` SHOULD be considered a primary key for our purposes.
2121

2222
```mermaid
2323
erDiagram
24-
direction LR
2524
Guild
2625
GuildMember
2726
```
2827

28+
# Matches Played by Users
29+
2930
We split this into three tables.
3031

3132
```mermaid
@@ -52,30 +53,62 @@ erDiagram
5253

5354
##### Entity Relation Diagram for Matches, storing the data that would be reported by a user.
5455

55-
The winner of the match can be inferred by selecting the `MatchPlayer` record with the highest `win_count` among records with the same `match_id`.
56+
The winner of the match SHALL be inferred by selecting the `MatchPlayer` record with the highest `win_count` among records with the same `match_id`.
5657

5758
Note that `guild_id` is not stored by the `Match` table. When a match is reported for a particular `guild_id` (a unique ID assigned by Discord for a particular Discord server), the match is reported for that "guild's" current season (see below).
5859

60+
# Seasons for Guilds
61+
5962
```mermaid
6063
erDiagram
6164
direction LR
6265
Match {
63-
int match_id
64-
int season_id
66+
int match_id PK
67+
int season_id FK
6568
datetime created_at
6669
}
6770
Season {
68-
int season_id
71+
int season_id PK
6972
string guild_id
7073
datetime start_at
7174
datetime end_at
7275
}
7376
Match }|--|| Season: "was played during"
74-
Guild ||--o{ Season: "has a current or past"
77+
Guild ||--o{ Season: "has a"
7578
```
7679

7780
##### Entity Relation Diagram for Seasons.
7881

7982
A guild's "current" season is a `Season` record for which the `guild_id` matches, and the system datetime is between `start_at` and `end_at`.
8083

81-
In addition, a `Season` in which participants will be designated an individual tier. Participants in a `Season` are `GuildMember` who report having participated in a `Match` during a `Season`.
84+
> Queries for a guild's current season should be optimized by creating an index on a guild.
85+
86+
A `Match` is played in a `Season` if the `season_id` matches a `Season` record's `season_id`.
87+
88+
In addition, a `Season` in which participants will be designated an individual tier. Participants in a `Season` are `GuildMember`s who report having participated in a `Match` during a `Season`.
89+
90+
# Tiers for Users Playing Matches
91+
92+
> We recommand some in-memory key-value database to store tiers for current seasons. This is not implemented for the current release of Grindcord.
93+
94+
For past seasons, Grindcord SHALL keep a record of each participating user's role.
95+
96+
```mermaid
97+
erDiagram
98+
direction LR
99+
UserSeasonTier {
100+
string user_id PK
101+
int season_id PK,FK
102+
string tier_role_id
103+
}
104+
Season {
105+
int season_id PK
106+
string guild_id PK
107+
datetime start_at
108+
datetime end_at
109+
}
110+
UserSeasonTier ||..|| User: "assigns a tier to"
111+
UserSeasonTier }|--|| Season: "determines tier in season"
112+
```
113+
114+
A `tier_role_id` is the `role_id` of a role in a Discord server.

apps/docsite/docs/intro.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ sidebar_position: 1
77

88
We have some user-friendly guides appropriate for all levels of expertise!
99

10-
# Reporting a set
11-
# Checking the leaderboard
12-
# Checking my sets
13-
# Checking other people's sets
10+
# For admins
11+
- Setting up Grindcord
12+
- Installing Grindcord
13+
- Permission and tier roles
14+
15+
# For users
16+
- Reporting a match
17+
- Checking the leaderboard
18+
- Checking my matches
19+
- by date
20+
- by win/loss
21+
- by character
22+
- Checking other people's matches
23+
24+
# Advanced: Self-hosting
25+
- Docker
26+
- Discord Bot
27+
- Bring your own database
28+
29+
# Advanced: Exporting data

0 commit comments

Comments
 (0)