-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#855 add before insert triggers to exclude rows from either allowlist…
…/denylist
- Loading branch information
1 parent
c3ccc5d
commit 4f98605
Showing
4 changed files
with
83 additions
and
36 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
volumes/miovision/sql/function/function-exclude_denylist_from_intersection_movements.sql
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,38 @@ | ||
CREATE OR REPLACE FUNCTION miovision_api.exclude_denylist_from_intersection_movements() | ||
RETURNS TRIGGER | ||
LANGUAGE plpgsql | ||
AS $BODY$ | ||
|
||
DECLARE row_in_im numeric = ( | ||
SELECT COUNT(*) | ||
FROM miovision_api.intersection_movements_denylist AS im | ||
WHERE | ||
im.intersection_uid = new.intersection_uid | ||
AND im.leg = new.leg | ||
AND im.movement_uid = new.movement_uid | ||
AND im.classification_uid = new.classification_uid | ||
); | ||
|
||
BEGIN | ||
IF (row_in_im) THEN | ||
RAISE NOTICE 'Row % is not being inserted. Already in intersection_movements_denylist table.', new; | ||
--Return null to stop insert. | ||
RETURN NULL; | ||
ELSE | ||
RETURN new; | ||
END IF; | ||
END; | ||
$BODY$; | ||
|
||
ALTER FUNCTION miovision_api.exclude_denylist_from_intersection_movements OWNER TO miovision_admins; | ||
|
||
GRANT EXECUTE ON miovision_api.exclude_denylist_from_intersection_movements TO miovision_api_bot; | ||
|
||
COMMENT ON miovision_api.exclude_denylist_from_intersection_movements | ||
IS 'Runs before insert into miovision_api.intersection_movements to prevent inserts that are on | ||
the denylist (miovision_api.intersection_movements_denylist).'; | ||
|
||
/*Test: | ||
INSERT INTO miovision_api.intersection_movements | ||
SELECT * FROM miovision_api.intersection_movements_denylist LIMIT 1; | ||
*/ |
38 changes: 38 additions & 0 deletions
38
volumes/miovision/sql/function/function-exclude_intersection_movements_from_denylist.sql
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,38 @@ | ||
CREATE OR REPLACE FUNCTION miovision_api.exclude_intersection_movements_from_denylist() | ||
RETURNS TRIGGER | ||
LANGUAGE plpgsql | ||
AS $BODY$ | ||
|
||
DECLARE row_in_im numeric = ( | ||
SELECT COUNT(*) | ||
FROM miovision_api.intersection_movements AS im | ||
WHERE | ||
im.intersection_uid = new.intersection_uid | ||
AND im.leg = new.leg | ||
AND im.movement_uid = new.movement_uid | ||
AND im.classification_uid = new.classification_uid | ||
); | ||
|
||
BEGIN | ||
IF (row_in_im) THEN | ||
RAISE NOTICE 'Row % is not being inserted. Already in intersection_movements table.', new; | ||
--Return null to stop insert. | ||
RETURN NULL; | ||
ELSE | ||
RETURN new; | ||
END IF; | ||
END; | ||
$BODY$; | ||
|
||
ALTER FUNCTION miovision_api.exclude_intersection_movements_from_denylist OWNER TO miovision_admins; | ||
|
||
GRANT EXECUTE ON miovision_api.exclude_intersection_movements_from_denylist TO miovision_api_bot; | ||
|
||
COMMENT ON miovision_api.exclude_intersection_movements_from_denylist | ||
IS 'Runs before insert into miovision_api.intersection_movements_denylist to prevent inserts | ||
that are already in intersections_movements (allowlist).'; | ||
|
||
/*Test: | ||
INSERT INTO miovision_api.intersection_movements_denylist | ||
SELECT * FROM miovision_api.intersection_movements LIMIT 1; | ||
*/ |
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