-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* initial discussions api schema and migration * rename migration * add new table to truncate lists * formatting * update postman, remove payload types, add constraint
- Loading branch information
Showing
10 changed files
with
1,953 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
CREATE TABLE IF NOT EXISTS system_intake_internal_grb_review_discussion_posts ( | ||
id UUID PRIMARY KEY NOT NULL, | ||
content TEXT NOT NULL, | ||
voting_role grb_reviewer_voting_role_type, | ||
grb_role grb_reviewer_role_type, | ||
system_intake_id UUID NOT NULL | ||
REFERENCES system_intakes(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
reply_to_id UUID | ||
REFERENCES system_intake_internal_grb_review_discussion_posts (id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
created_by UUID NOT NULL REFERENCES user_account(id), | ||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
modified_by UUID REFERENCES user_account(id), | ||
modified_at TIMESTAMP WITH TIME ZONE, | ||
CONSTRAINT is_admin_or_reviewer CHECK ( | ||
(voting_role IS NULL AND grb_role IS NULL) OR | ||
(voting_role IS NOT NULL AND grb_role IS NOT NULL) | ||
) | ||
); | ||
|
||
CREATE OR REPLACE FUNCTION prevent_nested_replies_fn() RETURNS TRIGGER AS $$ | ||
DECLARE | ||
parent_reply_to_id UUID; | ||
BEGIN | ||
-- If reply_to_id is not NULL, check if it points to a top-level post | ||
IF NEW.reply_to_id IS NOT NULL THEN | ||
-- Fetch the reply_to_id of the parent post | ||
SELECT reply_to_id INTO parent_reply_to_id | ||
FROM system_intake_internal_grb_review_discussion_posts | ||
WHERE id = NEW.reply_to_id; | ||
|
||
-- If parent_reply_to_id is NOT NULL, the parent post is a reply, so raise an error | ||
IF parent_reply_to_id IS NOT NULL THEN | ||
RAISE EXCEPTION 'Replies can only be made to top-level posts'; | ||
END IF; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER prevent_nested_replies_trigger | ||
BEFORE INSERT OR UPDATE ON system_intake_internal_grb_review_discussion_posts | ||
FOR EACH ROW EXECUTE FUNCTION prevent_nested_replies_fn(); |
Oops, something went wrong.