Skip to content

Commit

Permalink
Update selab_script.sql
Browse files Browse the repository at this point in the history
triggers/functies/restrictions
  • Loading branch information
DRIESASTER authored Feb 27, 2024
1 parent 48fb1d0 commit 648ef38
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions backend/selab_script.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,38 @@ CREATE TABLE Bestand (
);


--checks

ALTER TABLE Project
ADD CONSTRAINT deadline_check CHECK (deadline >= CURRENT_DATE);

ALTER TABLE Groep ADD CONSTRAINT score_check CHECK (score BETWEEN 0 AND 20);

ALTER TABLE WebsiteUser ALTER COLUMN is_admin SET DEFAULT FALSE;

--zorgt ervoor dat er geen indieningen na deadline kunnen gebeuren
CREATE OR REPLACE FUNCTION check_indiening_voor_deadline()
RETURNS TRIGGER AS $$
DECLARE
project_deadline DATE;
BEGIN
SELECT deadline INTO project_deadline
FROM Project
WHERE id = NEW.project_id;

IF CURRENT_TIMESTAMP > project_deadline THEN
RAISE EXCEPTION 'Indiening is niet meer toegelaten na deadline';
END IF;

RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trg_check_indiening_voor_deadline
BEFORE INSERT ON Indiening
FOR EACH ROW
EXECUTE FUNCTION check_indiening_voor_deadline();




Expand Down

0 comments on commit 648ef38

Please sign in to comment.