2022-03-18 07:39:30 +00:00
|
|
|
# Backend Database Specification
|
|
|
|
|
|
|
|
The backend will use sqlite to store all state for storing players (and their
|
|
|
|
IDs, and paired state), and games in progress.
|
|
|
|
|
|
|
|
## Table definitions
|
|
|
|
|
|
|
|
```
|
|
|
|
// enable foreign_keys restrictions
|
|
|
|
PRAGMA foreign_keys = ON;
|
|
|
|
|
|
|
|
// fields should be self explanatory for the players table
|
2022-04-27 02:15:53 +00:00
|
|
|
|
|
|
|
// "phrase" is used to connect players with identical "phrase" text to make it
|
|
|
|
// easier to connect with the player one wants to play with
|
|
|
|
|
2022-03-18 07:39:30 +00:00
|
|
|
CREATE TABLE players (id INTEGER PRIMARY KEY NOT NULL,
|
2022-04-01 10:49:50 +00:00
|
|
|
date_added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2022-03-18 08:03:07 +00:00
|
|
|
game_id INTEGER,
|
2022-04-27 02:15:53 +00:00
|
|
|
phrase TEXT,
|
2022-03-18 08:03:07 +00:00
|
|
|
FOREIGN KEY(game_id) REFERENCES games(id) ON DELETE CASCADE);
|
2022-03-18 07:39:30 +00:00
|
|
|
|
|
|
|
// "cyan_player" and "magenta_player" should correspond to an existing entry in
|
|
|
|
// table "players".
|
|
|
|
|
|
|
|
// "board" is as explained in backend_protocol_specification.md
|
|
|
|
|
|
|
|
// "status" is "0" for cyan's turn, "1" for magenta's turn, "2" for cyan won,
|
|
|
|
// "3" for magenta won, "4" for draw.
|
|
|
|
|
2022-03-18 08:03:07 +00:00
|
|
|
CREATE TABLE games (id INTEGER PRIMARY KEY NOT NULL,
|
2022-03-21 04:25:32 +00:00
|
|
|
cyan_player INTEGER UNIQUE,
|
|
|
|
magenta_player INTEGER UNIQUE,
|
2022-04-01 10:49:50 +00:00
|
|
|
date_added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2022-03-18 07:39:30 +00:00
|
|
|
board TEXT NOT NULL,
|
|
|
|
status INTEGER NOT NULL,
|
2022-04-01 10:49:50 +00:00
|
|
|
turn_time_start TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2022-03-21 04:25:32 +00:00
|
|
|
FOREIGN KEY(cyan_player) REFERENCES players (id) ON DELETE SET NULL,
|
|
|
|
FOREIGN KEY(magenta_player) REFERENCES players (id) ON DELETE SET NULL);
|
2022-04-29 08:16:32 +00:00
|
|
|
|
|
|
|
// "type" is one of the four possible emotes
|
|
|
|
|
|
|
|
CREATE TABLE emotes (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
|
|
|
date_added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
receiver_id INTEGER NOT NULL,
|
|
|
|
FOREIGN KEY(receiver_id) REFERENCES players (id) ON DELETE CASCADE);
|
2022-03-18 07:39:30 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
"date" entries are used for garbage collection of the database. A predefined
|
|
|
|
length of time will be used to cleanup stale entries. Whenever an entry in the
|
|
|
|
"games" table is updated, the "date" entry will be updated as well.
|