From 3ba446be5b535beb308879beb417583e62624fb0 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 26 Feb 2024 00:12:13 +0100 Subject: [PATCH] Splitting migration scripts --- backend/migrations/0010.sql | 50 ------------------- backend/migrations/0010_users.sql | 5 ++ backend/migrations/0020_projects.sql | 7 +++ backend/migrations/0030_time_reports.sql | 18 +++++++ .../0040_time_report_collections.sql | 7 +++ backend/migrations/0050_user_roles.sql | 7 +++ 6 files changed, 44 insertions(+), 50 deletions(-) delete mode 100644 backend/migrations/0010.sql create mode 100644 backend/migrations/0010_users.sql create mode 100644 backend/migrations/0020_projects.sql create mode 100644 backend/migrations/0030_time_reports.sql create mode 100644 backend/migrations/0040_time_report_collections.sql create mode 100644 backend/migrations/0050_user_roles.sql diff --git a/backend/migrations/0010.sql b/backend/migrations/0010.sql deleted file mode 100644 index df314b1..0000000 --- a/backend/migrations/0010.sql +++ /dev/null @@ -1,50 +0,0 @@ -PRAGMA foreign_keys = ON; - -CREATE TABLE IF NOT EXISTS users ( - id INTEGER PRIMARY KEY, - 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 diff --git a/backend/migrations/0010_users.sql b/backend/migrations/0010_users.sql new file mode 100644 index 0000000..d36847e --- /dev/null +++ b/backend/migrations/0010_users.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY, + username VARCHAR(255) NOT NULL, + password VARCHAR(255) NOT NULL +); \ No newline at end of file diff --git a/backend/migrations/0020_projects.sql b/backend/migrations/0020_projects.sql new file mode 100644 index 0000000..293aea5 --- /dev/null +++ b/backend/migrations/0020_projects.sql @@ -0,0 +1,7 @@ +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) +); \ No newline at end of file diff --git a/backend/migrations/0030_time_reports.sql b/backend/migrations/0030_time_reports.sql new file mode 100644 index 0000000..b860a35 --- /dev/null +++ b/backend/migrations/0030_time_reports.sql @@ -0,0 +1,18 @@ +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; \ No newline at end of file diff --git a/backend/migrations/0040_time_report_collections.sql b/backend/migrations/0040_time_report_collections.sql new file mode 100644 index 0000000..054593b --- /dev/null +++ b/backend/migrations/0040_time_report_collections.sql @@ -0,0 +1,7 @@ +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 diff --git a/backend/migrations/0050_user_roles.sql b/backend/migrations/0050_user_roles.sql new file mode 100644 index 0000000..054593b --- /dev/null +++ b/backend/migrations/0050_user_roles.sql @@ -0,0 +1,7 @@ +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