-
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.
- Loading branch information
Showing
3 changed files
with
47 additions
and
5 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
4 changes: 0 additions & 4 deletions
4
SQL Scripts/triggers/layer_contexts/on_layer_context_created_check_open_edit.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 |
---|---|---|
@@ -1,5 +1 @@ | ||
DROP TRIGGER IF EXISTS on_layer_context_created_check_open_edit ON public.layer_contexts; | ||
|
||
CREATE TRIGGER on_layer_context_created_check_open_edit | ||
AFTER INSERT ON public.layer_contexts FOR EACH ROW | ||
EXECUTE PROCEDURE check_layer_context_for_open_edit (); |
46 changes: 46 additions & 0 deletions
46
supabase/migrations/20240523204158_remove_layer_context_trigger.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,46 @@ | ||
drop trigger if exists "on_layer_context_created_check_open_edit" on "public"."layer_contexts"; | ||
|
||
set check_function_bodies = off; | ||
|
||
CREATE OR REPLACE FUNCTION public.check_layer_context_for_open_edit() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
DECLARE | ||
_project_id uuid; | ||
_context_name VARCHAR; | ||
_is_project_default BOOLEAN; | ||
_is_open_edit BOOLEAN; | ||
_record RECORD; | ||
_project_group_id uuid; | ||
_role_id uuid; | ||
_id uuid; | ||
BEGIN | ||
-- See if the layer is in the default context on an open edit project | ||
SELECT c.project_id, c.name, c.is_project_default INTO _project_id, _context_name, _is_project_default FROM public.contexts c WHERE c.id = NEW.context_id; | ||
SELECT is_open_edit INTO _is_open_edit FROM public.projects p WHERE p.id = _project_id; | ||
|
||
RAISE LOG 'check_layer_context_for_open_edit'; | ||
|
||
IF _is_open_edit AND _is_project_default IS TRUE THEN | ||
-- Get the project group | ||
SELECT (id) INTO _project_group_id FROM public.project_groups WHERE project_id = _project_id and is_default = TRUE; | ||
|
||
-- Get the role_id | ||
SELECT g.role_id INTO _role_id FROM public.default_groups g WHERE g.group_type = 'layer' AND g.is_default = TRUE; | ||
|
||
-- Add all project members to default context | ||
FOR _record IN SELECT * FROM public.group_users WHERE group_type = 'project' AND type_id = _project_group_id | ||
LOOP | ||
INSERT INTO public.context_users (context_id, user_id, role_id) | ||
VALUES (NEW.context_id,_record.user_id, _role_id); | ||
END LOOP; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END | ||
$function$ | ||
; | ||
|
||
|