optimized schema
This commit is contained in:
parent
80a8f6775c
commit
d174f74408
3 changed files with 125 additions and 60 deletions
|
|
@ -3,7 +3,8 @@
|
|||
```mermaid
|
||||
erDiagram
|
||||
user {
|
||||
string name PK
|
||||
serial id PK
|
||||
string name
|
||||
}
|
||||
|
||||
game {
|
||||
|
|
@ -11,17 +12,33 @@ erDiagram
|
|||
int score
|
||||
time playtime
|
||||
date date
|
||||
string username FK
|
||||
int user_id FK
|
||||
}
|
||||
|
||||
user ||--O{ game : "played"
|
||||
|
||||
user_data {
|
||||
string username PK
|
||||
user_scores {
|
||||
int user_id PK
|
||||
int highscore
|
||||
int total_score
|
||||
int total_playtime
|
||||
int average_score
|
||||
int games_played
|
||||
}
|
||||
```
|
||||
|
||||
lb_highscore {
|
||||
int rank
|
||||
int user_id
|
||||
int highscore
|
||||
}
|
||||
|
||||
lb_total_playtime {
|
||||
int rank
|
||||
int user_id
|
||||
time total_playtime
|
||||
}
|
||||
|
||||
user ||--O{ game : "played"
|
||||
user ||--|| user_scores : ""
|
||||
```
|
||||
`lb_highscore` and `lb_total_playtime` are views querying the `user_scores` table.
|
||||
|
||||
A trigger function on insert to the `user` table creates a new row in `user_scores`. Everytime a new `game` is inserted, the row is updated.
|
||||
Loading…
Add table
Add a link
Reference in a new issue