Skip to content

Commit

Permalink
feat: migration add-task-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
varun2948 committed Feb 6, 2024
1 parent 9142cc9 commit fd540d0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/backend/migrations/006-add-task-comment.sql
Original file line number Diff line number Diff line change
@@ -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;

10 changes: 10 additions & 0 deletions src/backend/migrations/revert/006-add-task-comment.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit fd540d0

Please sign in to comment.