diff --git a/backend/migrations/0010_users.sql b/backend/migrations/0010_users.sql index 75c286c..7cb23fd 100644 --- a/backend/migrations/0010_users.sql +++ b/backend/migrations/0010_users.sql @@ -1,5 +1,9 @@ CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, + userId TEXT DEFAULT (HEX(RANDOMBLOB(4))) NOT NULL UNIQUE, username VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL -); \ No newline at end of file +); + +CREATE INDEX IF NOT EXISTS users_username_index ON users (username); +CREATE INDEX IF NOT EXISTS users_userId_index ON users (userId); \ No newline at end of file diff --git a/backend/migrations/0020_projects.sql b/backend/migrations/0020_projects.sql index 293aea5..8592e75 100644 --- a/backend/migrations/0020_projects.sql +++ b/backend/migrations/0020_projects.sql @@ -1,7 +1,11 @@ CREATE TABLE IF NOT EXISTS projects ( id INTEGER PRIMARY KEY, - name VARCHAR(255) NOT NULL, + projectId TEXT DEFAULT (HEX(RANDOMBLOB(4))) NOT NULL UNIQUE, + name VARCHAR(255) NOT NULL UNIQUE, description TEXT NOT NULL, user_id INTEGER NOT NULL, FOREIGN KEY (user_id) REFERENCES users (id) -); \ No newline at end of file +); + +CREATE INDEX IF NOT EXISTS projects_projectId_index ON projects (projectId); +CREATE INDEX IF NOT EXISTS projects_user_id_index ON projects (user_id); \ No newline at end of file diff --git a/backend/migrations/0030_time_reports.sql b/backend/migrations/0030_time_reports.sql index b860a35..e8f3ec1 100644 --- a/backend/migrations/0030_time_reports.sql +++ b/backend/migrations/0030_time_reports.sql @@ -1,9 +1,10 @@ CREATE TABLE IF NOT EXISTS time_reports ( id INTEGER PRIMARY KEY, + reportId TEXT DEFAULT (HEX(RANDOMBLOB(6))) NOT NULL UNIQUE, project_id INTEGER NOT NULL, start DATETIME NOT NULL, end DATETIME NOT NULL, - FOREIGN KEY (project_id) REFERENCES projects (id) + FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE ); CREATE TRIGGER IF NOT EXISTS time_reports_start_before_end diff --git a/backend/migrations/0040_time_report_collections.sql b/backend/migrations/0040_time_report_collections.sql index 7dbe6bd..be406ff 100644 --- a/backend/migrations/0040_time_report_collections.sql +++ b/backend/migrations/0040_time_report_collections.sql @@ -1,7 +1,9 @@ CREATE TABLE IF NOT EXISTS report_collection ( id INTEGER PRIMARY KEY, + owner_id INTEGER NOT NULL, project_id INTEGER NOT NULL, date DATE NOT NULL, signed_by INTEGER, -- NULL if not signed + FOREIGN KEY (owner_id) REFERENCES users (id) FOREIGN KEY (signed_by) REFERENCES users (id) ); \ No newline at end of file diff --git a/backend/migrations/0050_user_roles.sql b/backend/migrations/0050_user_roles.sql index 054593b..32e03dc 100644 --- a/backend/migrations/0050_user_roles.sql +++ b/backend/migrations/0050_user_roles.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS user_roles ( user_id INTEGER NOT NULL, project_id INTEGER NOT NULL, - role STRING NOT NULL, + role STRING NOT NULL, -- 'admin' or 'member' FOREIGN KEY (user_id) REFERENCES users (id) FOREIGN KEY (project_id) REFERENCES projects (id) ); \ No newline at end of file