From fd540d0d68a092fe6acd17c2af98ef1852a7e662 Mon Sep 17 00:00:00 2001 From: Deepak Pradhan Date: Tue, 6 Feb 2024 15:52:58 +0545 Subject: [PATCH] feat: migration add-task-comment --- .../migrations/006-add-task-comment.sql | 30 +++++++++++++++++++ .../revert/006-add-task-comment.sql | 10 +++++++ 2 files changed, 40 insertions(+) create mode 100644 src/backend/migrations/006-add-task-comment.sql create mode 100644 src/backend/migrations/revert/006-add-task-comment.sql diff --git a/src/backend/migrations/006-add-task-comment.sql b/src/backend/migrations/006-add-task-comment.sql new file mode 100644 index 0000000000..95bbc63da6 --- /dev/null +++ b/src/backend/migrations/006-add-task-comment.sql @@ -0,0 +1,30 @@ +-- ## Migration to create task_comment table + +-- ## Apply Migration +-- Start a transaction +BEGIN; + +-- Create the 'task_comment' table if it doesn't exist +CREATE TABLE IF NOT EXISTS public.task_comment ( + id SERIAL PRIMARY KEY, + task_id INT NOT NULL, + project_id INT NOT NULL, + comment_text TEXT NOT NULL, + commented_by INT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + + -- Add foreign key constraint for task_id referencing a task table + CONSTRAINT fk_task_id FOREIGN KEY (task_id, project_id) REFERENCES tasks(id, project_id), + + -- Add foreign key constraint for project_id referencing a project table + CONSTRAINT fk_project_id FOREIGN KEY (project_id) REFERENCES projects(id), + + -- Add foreign key constraint for user_id referencing a user table + CONSTRAINT fk_user_id FOREIGN KEY (commented_by) REFERENCES users(id) + +); +ALTER TABLE public.task_comment OWNER TO fmtm; + +-- Commit the transaction +COMMIT; + diff --git a/src/backend/migrations/revert/006-add-task-comment.sql b/src/backend/migrations/revert/006-add-task-comment.sql new file mode 100644 index 0000000000..e56b8b8332 --- /dev/null +++ b/src/backend/migrations/revert/006-add-task-comment.sql @@ -0,0 +1,10 @@ + +## Revert Migration (comment above, uncomment below) +-- Start a transaction +BEGIN; + +-- Drop the 'task_comment' table if it exists +DROP TABLE IF EXISTS public.task_comment; + +-- Commit the transaction +COMMIT; \ No newline at end of file