From b5fd6a1c4b6fbfc71fe193de2660a312a9a788f6 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 20 Feb 2024 20:24:53 +0100 Subject: [PATCH] Draft version of the SQL tables --- backend/migrations/0010.sql | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/backend/migrations/0010.sql b/backend/migrations/0010.sql index 11be51c..df314b1 100644 --- a/backend/migrations/0010.sql +++ b/backend/migrations/0010.sql @@ -5,3 +5,46 @@ CREATE TABLE IF NOT EXISTS users ( username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL ); + +CREATE TABLE IF NOT EXISTS projects ( + id INTEGER PRIMARY KEY, + name VARCHAR(255) NOT NULL, + description TEXT NOT NULL, + user_id INTEGER NOT NULL, + FOREIGN KEY (user_id) REFERENCES users (id) +); + +CREATE TABLE IF NOT EXISTS time_reports ( + id INTEGER PRIMARY KEY, + project_id INTEGER NOT NULL, + start DATETIME NOT NULL, + end DATETIME NOT NULL, + FOREIGN KEY (project_id) REFERENCES projects (id) +); + +CREATE TRIGGER IF NOT EXISTS time_reports_start_before_end + BEFORE INSERT ON time_reports + FOR EACH ROW + BEGIN + SELECT + CASE + WHEN NEW.start >= NEW.end THEN + RAISE (ABORT, 'start must be before end') + END; + END; + +CREATE TABLE IF NOT EXISTS report_collection ( + id INTEGER PRIMARY KEY, + project_id INTEGER NOT NULL, + date DATE NOT NULL, + signed_by INTEGER, -- NULL if not signed + FOREIGN KEY (signed_by) REFERENCES users (id) +); + +CREATE TABLE IF NOT EXISTS user_roles ( + user_id INTEGER NOT NULL, + project_id INTEGER NOT NULL, + role STRING NOT NULL, + FOREIGN KEY (user_id) REFERENCES users (id) + FOREIGN KEY (project_id) REFERENCES projects (id) +); \ No newline at end of file