From 8cd9f26321316a28925b374a3aace5b47ba394cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20J=C3=B8dest=C3=B8l=20Haugland?= Date: Mon, 25 Apr 2022 12:31:58 +0200 Subject: [PATCH] Update Persistence --- Persistence.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/Persistence.md b/Persistence.md index cfe36d1..b7071d5 100644 --- a/Persistence.md +++ b/Persistence.md @@ -1 +1,58 @@ -## Persistence will be added once database and back-end is finished \ No newline at end of file +All data is stored in the MySQL-database. User sessions are stored in server memory. + +#### ER-Diagram + +![entityRelationshipDiagram](uploads/c1ff984303b489fdbff06b26705af2a0/entityRelationshipDiagram.png) + + +##### The SQL calls to create the database tables needed: + +```sql +-- WARNING: Will delete EVERYTHING in the database! + +DROP TABLE IF EXISTS matches; +DROP TABLE IF EXISTS teams; +DROP TABLE IF EXISTS tournaments; +DROP TABLE IF EXISTS users; + +-- Create the tables +CREATE TABLE tournaments ( + id INTEGER PRIMARY KEY AUTO_INCREMENT, + name TEXT NOT NULL, + description TEXT, + prize TEXT, + teamLimit INTEGER NOT NULL, + startTime DATETIME NOT NULL, + endTime DATETIME NOT NULL +); + +CREATE TABLE teams ( + id INTEGER PRIMARY KEY AUTO_INCREMENT, + tournamentId INTEGER NOT NULL, + name TEXT NOT NULL, + + FOREIGN KEY (tournamentId) REFERENCES tournaments (id) ON DELETE CASCADE +); + +CREATE TABLE matches ( + id INTEGER PRIMARY KEY AUTO_INCREMENT, + tournamentId INTEGER NOT NULL, + parentMatchId INTEGER, + team1Id INTEGER, + team2Id INTEGER, + winnerId INTEGER, + tier INTEGER, + + FOREIGN KEY (tournamentId) REFERENCES tournaments (id) ON DELETE CASCADE, + FOREIGN KEY (team1Id) REFERENCES teams (id) ON DELETE SET NULL, + FOREIGN KEY (team2Id) REFERENCES teams (id) ON DELETE SET NULL, + FOREIGN KEY (winnerId) REFERENCES teams (id) ON DELETE SET NULL +); + +CREATE TABLE users ( + id INTEGER PRIMARY KEY AUTO_INCREMENT, + googleId TEXT, + name TEXT, + email TEXT NOT NULL, + isManager BOOLEAN NOT NULL +); \ No newline at end of file