Skip to content

Commit fc9e84e

Browse files
🤡 Remove profanity
1 parent c86f547 commit fc9e84e

File tree

2 files changed

+129
-3
lines changed

2 files changed

+129
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
--! Previous: sha1:7b3014cc9d2637d62f0fee1b2ea18fb6d5266dc1
2+
--! Hash: sha1:78bf70518119fa25c1cf0cda3d23d47c4936ea0d
3+
4+
-- Enter migration here
5+
CREATE OR REPLACE FUNCTION public.replace_data_source(data_layer_id integer, data_source_id integer, source_layer text, bounds numeric[], gl_styles jsonb) RETURNS void
6+
LANGUAGE plpgsql SECURITY DEFINER
7+
AS $$
8+
declare
9+
old_source_id integer;
10+
old_source_type text;
11+
old_metadata_is_dynamic boolean;
12+
dl_template_id text;
13+
begin
14+
-- first, determine if a related table_of_contents_item has
15+
-- data_library_template_id set. If so, we need to update the
16+
-- related Toc items that have copied_from_data_library_template_id
17+
-- matching.
18+
19+
select data_library_template_id into dl_template_id from table_of_contents_items where table_of_contents_items.data_layer_id = replace_data_source.data_layer_id and data_library_template_id is not null limit 1;
20+
21+
22+
select data_layers.data_source_id into old_source_id from data_layers where id = replace_data_source.data_layer_id;
23+
select type into old_source_type from data_sources where id = old_source_id;
24+
select metadata is null and (old_source_type = 'arcgis-vector' or old_source_type = 'arcgis-dynamic-mapserver') into old_metadata_is_dynamic from table_of_contents_items where table_of_contents_items.data_layer_id = replace_data_source.data_layer_id limit 1;
25+
insert into archived_data_sources (
26+
data_source_id,
27+
data_layer_id,
28+
version,
29+
mapbox_gl_style,
30+
changelog,
31+
source_layer,
32+
bounds,
33+
sublayer,
34+
sublayer_type,
35+
dynamic_metadata,
36+
project_id
37+
) values (
38+
old_source_id,
39+
replace_data_source.data_layer_id,
40+
(
41+
select
42+
coalesce(max(version), 0) + 1
43+
from
44+
archived_data_sources
45+
where archived_data_sources.data_layer_id = replace_data_source.data_layer_id
46+
),
47+
(
48+
select
49+
mapbox_gl_styles
50+
from
51+
data_layers
52+
where id = replace_data_source.data_layer_id
53+
),
54+
(select changelog from data_sources where id = replace_data_source.data_source_id),
55+
(select data_layers.source_layer from data_layers where data_layers.id = replace_data_source.data_layer_id),
56+
(select table_of_contents_items.bounds from table_of_contents_items where table_of_contents_items.data_layer_id = replace_data_source.data_layer_id and table_of_contents_items.bounds is not null limit 1),
57+
(select sublayer from data_layers where id = data_layer_id),
58+
(select sublayer_type from data_layers where id = data_layer_id),
59+
old_metadata_is_dynamic,
60+
(select project_id from data_sources where id = replace_data_source.data_source_id)
61+
);
62+
63+
if dl_template_id is not null then
64+
update
65+
data_sources
66+
set data_library_template_id = dl_template_id
67+
where
68+
id = replace_data_source.data_source_id or
69+
id = any((
70+
select
71+
data_layers.data_source_id
72+
from
73+
data_layers
74+
where
75+
id = any (
76+
select
77+
table_of_contents_items.data_layer_id
78+
from
79+
table_of_contents_items
80+
where
81+
copied_from_data_library_template_id = dl_template_id or
82+
data_library_template_id = dl_template_id
83+
)
84+
)) or id = any ((
85+
select
86+
data_layers.data_source_id
87+
from
88+
data_layers
89+
where
90+
id = replace_data_source.data_layer_id
91+
));
92+
end if;
93+
94+
update
95+
data_layers
96+
set
97+
data_source_id = replace_data_source.data_source_id,
98+
source_layer = replace_data_source.source_layer,
99+
mapbox_gl_styles = coalesce(
100+
gl_styles, data_layers.mapbox_gl_styles
101+
),
102+
sublayer = null
103+
where
104+
id = replace_data_source.data_layer_id;
105+
106+
if dl_template_id is not null then
107+
update
108+
data_layers
109+
set
110+
data_source_id = replace_data_source.data_source_id,
111+
source_layer = replace_data_source.source_layer
112+
where
113+
id = any (
114+
select table_of_contents_items.data_layer_id from table_of_contents_items where copied_from_data_library_template_id = dl_template_id
115+
);
116+
end if;
117+
118+
update
119+
table_of_contents_items
120+
set bounds = replace_data_source.bounds
121+
where
122+
table_of_contents_items.data_layer_id = replace_data_source.data_layer_id or (
123+
case
124+
when dl_template_id is not null then copied_from_data_library_template_id = dl_template_id
125+
else false
126+
end
127+
);
128+
end;
129+
$$;

packages/api/schema.sql

-3
Original file line numberDiff line numberDiff line change
@@ -14375,9 +14375,6 @@ CREATE FUNCTION public.replace_data_source(data_layer_id integer, data_source_id
1437514375

1437614376
select data_library_template_id into dl_template_id from table_of_contents_items where table_of_contents_items.data_layer_id = replace_data_source.data_layer_id and data_library_template_id is not null limit 1;
1437714377

14378-
if dl_template_id is null then
14379-
raise exception 'fuck you %', dl_template_id;
14380-
end if;
1438114378

1438214379
select data_layers.data_source_id into old_source_id from data_layers where id = replace_data_source.data_layer_id;
1438314380
select type into old_source_type from data_sources where id = old_source_id;

0 commit comments

Comments
 (0)