FabulaVotes/db/00_create-tables.sql
trotFunky 9911895b5b v1.0: First production version
This first version allows login of pre-existing users, creation and update of truths
by admins, vote on the truths by users, their display as well as a simple graph
for the vote results.
Everything persisting in a SQLite database.
2024-07-23 21:51:42 +01:00

35 lines
1.1 KiB
SQL

CREATE TABLE IF NOT EXISTS Players (
id INTEGER PRIMARY KEY AUTOINCREMENT,
is_admin INTEGER NOT NULL DEFAULT 0,
name VARCHAR NOT NULL,
pwd_hash VARCHAR NOT NULL,
picture VARCHAR
);
CREATE TABLE IF NOT EXISTS Truths (
id INTEGER PRIMARY KEY AUTOINCREMENT,
week INTEGER NOT NULL CHECK (week > 0),
number INTEGER NOT NULL CHECK (number > 0),
author_id INTEGER NOT NULL,
rendered_text VARCHAR NOT NULL,
raw_text VARCHAR NOT NULL,
FOREIGN KEY (author_id) REFERENCES Players(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS Votes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
truth_id INTEGER NOT NULL,
voter_id INTEGER NOT NULL,
voted_id INTEGER NOT NULL,
FOREIGN KEY (truth_id) REFERENCES Truths(id) ON DELETE CASCADE,
FOREIGN KEY (voter_id) REFERENCES Players(id) ON DELETE CASCADE,
FOREIGN KEY (voted_id) REFERENCES Players(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS AuthTokens (
id INTEGER PRIMARY KEY AUTOINCREMENT,
player_id INTEGER NOT NULL,
token VARCHAR NOT NULL,
max_timestamp INTEGER NOT NULL,
FOREIGN KEY (player_id) REFERENCES Players(id) ON DELETE CASCADE
);