-
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.
Merge branch 'develop' of https://github.com/recogito/recogito-server …
…into develop
- Loading branch information
Showing
4 changed files
with
113 additions
and
11 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,31 @@ | ||
DO $$ | ||
DECLARE | ||
_layer_group_id uuid; | ||
_role_id uuid; | ||
_name varchar; | ||
_description varchar; | ||
_is_admin bool; | ||
_is_default bool; | ||
_is_read_only bool; | ||
_layer_id uuid; | ||
BEGIN | ||
-- Get the read-only default group | ||
FOR _role_id, _name, _description, _is_admin, _is_default, _is_read_only | ||
IN SELECT dg.role_id, dg.name, dg.description, dg.is_admin, dg.is_default, dg.is_read_only | ||
FROM public.default_groups dg | ||
WHERE dg.group_type = 'layer' AND dg.is_read_only IS TRUE | ||
LOOP | ||
-- Loop through all layers | ||
FOR _layer_id IN SELECT l.id FROM public.layers l | ||
LOOP | ||
IF NOT EXISTS(SELECT 1 FROM public.layer_groups lg WHERE lg.layer_id = _layer_id AND lg.is_read_only IS TRUE) | ||
THEN | ||
_layer_group_id = extensions.uuid_generate_v4(); | ||
INSERT INTO public.layer_groups | ||
(id, layer_id, role_id, name, description, is_admin, is_default, is_read_only) | ||
VALUES (_layer_group_id, _layer_id, _role_id, _name, _description, _is_admin, _is_default, _is_read_only); | ||
END IF; | ||
END LOOP; | ||
END LOOP; | ||
END | ||
$$ |
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
69 changes: 69 additions & 0 deletions
69
supabase/migrations/20241018181235_read-only-migration.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,69 @@ | ||
set check_function_bodies = off; | ||
|
||
CREATE OR REPLACE FUNCTION public.create_default_layer_groups() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
DECLARE | ||
_layer_group_id uuid; | ||
_role_id uuid; | ||
_name varchar; | ||
_description varchar; | ||
_is_admin bool; | ||
_is_default bool; | ||
_is_read_only bool; | ||
BEGIN | ||
FOR _role_id, _name, _description, _is_admin, _is_default, _is_read_only | ||
IN SELECT role_id, name, description, is_admin, is_default, is_read_only | ||
FROM public.default_groups | ||
WHERE group_type = 'layer' | ||
LOOP | ||
_layer_group_id = extensions.uuid_generate_v4(); | ||
INSERT INTO public.layer_groups | ||
(id, layer_id, role_id, name, description, is_admin, is_default, is_read_only) | ||
VALUES (_layer_group_id, NEW.id, _role_id, _name, _description, _is_admin, _is_default, _is_read_only); | ||
|
||
IF _is_admin IS TRUE AND NEW.created_by IS NOT NULL THEN | ||
INSERT INTO public.group_users (group_type, type_id, user_id) | ||
VALUES ('layer', _layer_group_id, NEW.created_by); | ||
END IF; | ||
END LOOP; | ||
RETURN NEW; | ||
END | ||
$function$ | ||
; | ||
|
||
DO $$ | ||
DECLARE | ||
_layer_group_id uuid; | ||
_role_id uuid; | ||
_name varchar; | ||
_description varchar; | ||
_is_admin bool; | ||
_is_default bool; | ||
_is_read_only bool; | ||
_layer_id uuid; | ||
BEGIN | ||
-- Get the read-only default group | ||
FOR _role_id, _name, _description, _is_admin, _is_default, _is_read_only | ||
IN SELECT dg.role_id, dg.name, dg.description, dg.is_admin, dg.is_default, dg.is_read_only | ||
FROM public.default_groups dg | ||
WHERE dg.group_type = 'layer' AND dg.is_read_only IS TRUE | ||
LOOP | ||
-- Loop through all layers | ||
FOR _layer_id IN SELECT l.id FROM public.layers l | ||
LOOP | ||
IF NOT EXISTS(SELECT 1 FROM public.layer_groups lg WHERE lg.layer_id = _layer_id AND lg.is_read_only IS TRUE) | ||
THEN | ||
_layer_group_id = extensions.uuid_generate_v4(); | ||
INSERT INTO public.layer_groups | ||
(id, layer_id, role_id, name, description, is_admin, is_default, is_read_only) | ||
VALUES (_layer_group_id, _layer_id, _role_id, _name, _description, _is_admin, _is_default, _is_read_only); | ||
END IF; | ||
END LOOP; | ||
END LOOP; | ||
END | ||
$$ | ||
|
||
|