RaspberryRocketeer/backend
2022-12-28 15:39:58 +01:00
..
api overhauled structure, leaderboardRoute.ts and userRoute.ts working 2022-12-28 15:39:58 +01:00
db overhauled structure, leaderboardRoute.ts and userRoute.ts working 2022-12-28 15:39:58 +01:00
README.md optimized schema 2022-12-13 09:50:33 +01:00

Database Schema

erDiagram
    user {
        serial id PK
        string name
    }

    game {
        serial game_id PK
        int score
        time playtime
        date date
        int user_id FK
    }

    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.