You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/api/migrations/current.sql
-271
Original file line number
Diff line number
Diff line change
@@ -4,274 +4,3 @@ alter table sketch_classes add column if not exists filter_api_server_location t
4
4
5
5
altertype sketch_geometry_type add value if not exists 'FILTERED_PLANNING_UNITS';
6
6
7
-
set role seasketch_superuser;
8
-
deletefrom sketch_classes where project_id = (select id from projects where slug ='superuser') and name ='Filtered Planning Units';
9
-
10
-
insert into sketch_classes(
11
-
project_id,
12
-
name,
13
-
geometry_type,
14
-
mapbox_gl_style,
15
-
is_template,
16
-
template_description
17
-
) values (
18
-
(select id from projects where slug ='superuser'),
19
-
'Filtered Planning Units',
20
-
'FILTERED_PLANNING_UNITS'::sketch_geometry_type,
21
-
'{}'::jsonb,
22
-
true,
23
-
'Filter polygons by criteria. Requires an API server.'
24
-
) on conflict do nothing;
25
-
26
-
select initialize_sketch_class_form_from_template((select id from sketch_classes where name ='Filtered Planning Units'and is_template = true), (select id from forms where is_template = true and template_type ='SKETCHES'and template_name ='Basic Template'));
27
-
set role postgres;
28
-
29
-
GRANTupdate (filter_api_server_location) on sketch_classes to seasketch_user;
30
-
GRANTupdate (filter_api_version) on sketch_classes to seasketch_user;
31
-
32
-
deletefrom form_element_types where component_name ='FilterInput';
33
-
insert into form_element_types (
34
-
component_name,
35
-
label,
36
-
is_input,
37
-
is_surveys_only
38
-
) values (
39
-
'FilterInput',
40
-
'Filter Input',
41
-
true,
42
-
false
43
-
);
44
-
45
-
CREATE OR REPLACEFUNCTIONpublic.before_sketch_insert_or_update() RETURNS trigger
46
-
LANGUAGE plpgsql SECURITY DEFINER
47
-
AS $$
48
-
declare
49
-
class_geometry_type sketch_geometry_type;
50
-
allow_multi boolean;
51
-
incoming_geometry_type text;
52
-
new_geometry_type text;
53
-
parent_collection_id int;
54
-
begin
55
-
select
56
-
geometry_type,
57
-
sketch_classes.allow_multi
58
-
into
59
-
class_geometry_type,
60
-
allow_multi,
61
-
incoming_geometry_type
62
-
from
63
-
sketch_classes
64
-
where
65
-
id =NEW.sketch_class_id;
66
-
if NEW.folder_idis not nullandNEW.collection_idis not null then
67
-
raise exception 'Parent cannot be to both folder and collection';
68
-
end if;
69
-
if class_geometry_type ='COLLECTION' then
70
-
-- Also check for parent collection of parent folder (recursively)
71
-
if NEW.collection_idis not null then
72
-
if (select get_parent_collection_id('sketch', NEW.collection_id)) is not null then
73
-
raise exception 'Nested collections are not allowed';
74
-
end if;
75
-
elsif NEW.folder_idis not null then
76
-
if (select get_parent_collection_id('sketch_folder', NEW.folder_id)) is not null then
77
-
raise exception 'Nested collections are not allowed';
78
-
end if;
79
-
end if;
80
-
-- geom must be present unless a collection
81
-
if NEW.geomis not nullorNEW.user_geomis not null then
82
-
raise exception 'Collections should not have geometry';
83
-
else
84
-
-- no nested collections
85
-
if NEW.collection_idis not null then
86
-
raise exception 'Nested collections are not allowed';
87
-
else
88
-
return NEW;
89
-
end if;
90
-
end if;
91
-
elsif class_geometry_type ='FILTERED_PLANNING_UNITS' then
92
-
-- Also check for parent collection of parent folder (recursively)
93
-
if NEW.collection_idis not null then
94
-
raise exception 'Filtered planning units cannot be part of a collection';
95
-
elsif NEW.folder_idis not null then
96
-
if (select get_parent_collection_id('sketch_folder', NEW.folder_id)) is not null then
97
-
raise exception 'Filtered planning units cannot be part of a collection';
98
-
end if;
99
-
end if;
100
-
-- geom must be present unless a collection
101
-
if NEW.geomis not nullorNEW.user_geomis not null then
102
-
raise exception 'Filtered planning units should not have geometry';
103
-
else
104
-
-- no nested collections
105
-
if NEW.collection_idis not null then
106
-
raise exception 'Filtered planning units cannot be part of a collection';
107
-
else
108
-
return NEW;
109
-
end if;
110
-
end if;
111
-
else
112
-
select geometrytype(NEW.user_geom) into new_geometry_type;
113
-
-- geometry type must match sketch_class.geometry_type and sketch_class.allow_multi
114
-
if (new_geometry_type = class_geometry_type::text) or (allow_multi and new_geometry_type like'%'|| class_geometry_type::text) then
115
-
-- if specifying a collection_id, must be in it's valid_children
116
-
if NEW.collection_id is nullor not exists(select1from sketch_classes_valid_children where parent_id in (select sketch_class_id from sketches where id =NEW.collection_id)) or exists(select1from sketch_classes_valid_children where parent_id in (select sketch_class_id from sketches where id =NEW.collection_id) and child_id =NEW.sketch_class_id) then
117
-
return NEW;
118
-
else
119
-
raise exception 'Sketch is not a valid child of collection';
120
-
end if;
121
-
else
122
-
raise exception 'Geometry type does not match sketch class';
123
-
end if;
124
-
end if;
125
-
end;
126
-
$$;
127
-
128
-
129
-
CREATE OR REPLACEFUNCTIONurl_encode(input text)
130
-
RETURNS textAS $$
131
-
DECLARE
132
-
cleaned_input text;
133
-
output text :='';
134
-
ch text;
135
-
ch_code int;
136
-
BEGIN
137
-
-- Remove all extraneous whitespace from the input JSON text
grant execute on function sketches_filter_mvt_url to anon;
262
-
-- alter table sketches add column if not exists filter_mvt_url text generated always as (filter_state_to_search_string(properties, sketch_class_id)) stored;
263
-
264
-
-- grant select(filter_mvt_url) on sketches to anon;
265
-
266
-
deletefrom form_element_types where component_name ='CollapsibleGroup';
0 commit comments