Update Persistence

Jonas Jødestøl Haugland 2022-04-25 12:31:58 +02:00 committed by Felix Albrigtsen
parent 9ff6b8e559
commit 8cd9f26321

@ -1 +1,58 @@
## Persistence will be added once database and back-end is finished
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
);