forked from QGEP/datamodel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
13_import.sql
563 lines (520 loc) · 18.1 KB
/
13_import.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
-- create quarantine table
DROP TABLE IF EXISTS qgep_import.manhole_quarantine CASCADE;
CREATE TABLE qgep_import.manhole_quarantine
(
obj_id character varying(16),
identifier character varying(20),
situation_geometry geometry(POINTZ,:SRID),
co_shape integer,
co_diameter smallint,
co_material integer,
co_positional_accuracy integer,
co_level numeric(7,3),
_depth numeric(6,3),
_channel_usage_current integer,
ma_material integer,
ma_dimension1 smallint,
ma_dimension2 smallint,
ws_type text,
ma_function integer,
ss_function integer,
remark character varying(80),
wn_bottom_level numeric(7,3),
photo1 text,
photo2 text,
inlet_3_material smallint,
inlet_3_clear_height integer,
inlet_3_depth_m numeric(7,3),
inlet_4_material smallint,
inlet_4_clear_height integer,
inlet_4_depth_m numeric(7,3),
inlet_5_material smallint,
inlet_5_clear_height integer,
inlet_5_depth_m numeric(7,3),
inlet_6_material smallint,
inlet_6_clear_height integer,
inlet_6_depth_m numeric(7,3),
inlet_7_material smallint,
inlet_7_clear_height integer,
inlet_7_depth_m numeric(7,3),
outlet_1_material smallint,
outlet_1_clear_height integer,
outlet_1_depth_m numeric(7,3),
outlet_2_material smallint,
outlet_2_clear_height integer,
outlet_2_depth_m numeric(7,3),
structure_okay boolean DEFAULT false,
inlet_okay boolean DEFAULT false,
outlet_okay boolean DEFAULT false,
deleted boolean DEFAULT false,
quarantine_serial SERIAL PRIMARY KEY
);
-- create mobile view
CREATE OR REPLACE VIEW qgep_import.vw_manhole AS
SELECT DISTINCT ON (ws.obj_id) ws.obj_id,
ws.identifier,
(st_dump(ws.situation_geometry)).geom::geometry(POINTZ,:SRID) AS situation_geometry,
ws.co_shape,
ws.co_diameter,
ws.co_material,
ws.co_positional_accuracy,
ws.co_level,
ws._depth::numeric(6, 3) AS _depth,
ws._channel_usage_current,
ws.ma_material,
ws.ma_dimension1,
ws.ma_dimension2,
ws.ws_type,
ws.ma_function,
ws.ss_function,
ws.remark,
ws.wn_bottom_level,
NULL::text AS photo1,
NULL::text AS photo2,
NULL::smallint AS inlet_3_material,
NULL::integer AS inlet_3_clear_height,
NULL::numeric(7, 3) AS inlet_3_depth_m,
NULL::smallint AS inlet_4_material,
NULL::integer AS inlet_4_clear_height,
NULL::numeric(7, 3) AS inlet_4_depth_m,
NULL::smallint AS inlet_5_material,
NULL::integer AS inlet_5_clear_height,
NULL::numeric(7, 3) AS inlet_5_depth_m,
NULL::smallint AS inlet_6_material,
NULL::integer AS inlet_6_clear_height,
NULL::numeric(7, 3) AS inlet_6_depth_m,
NULL::smallint AS inlet_7_material,
NULL::integer AS inlet_7_clear_height,
NULL::numeric(7, 3) AS inlet_7_depth_m,
NULL::smallint AS outlet_1_material,
NULL::integer AS outlet_1_clear_height,
NULL::numeric(7, 3) AS outlet_1_depth_m,
NULL::smallint AS outlet_2_material,
NULL::integer AS outlet_2_clear_height,
NULL::numeric(7, 3) AS outlet_2_depth_m,
FALSE::boolean AS verified,
(CASE WHEN EXISTS ( SELECT TRUE FROM qgep_import.manhole_quarantine q WHERE q.obj_id = ws.obj_id )
THEN TRUE
ELSE FALSE
END) AS in_quarantine,
FALSE::boolean AS deleted
FROM qgep_od.vw_qgep_wastewater_structure ws;
-- create triggerfunction and trigger for mobile view
CREATE OR REPLACE FUNCTION qgep_import.vw_manhole_insert_into_quarantine_or_delete() RETURNS trigger AS $BODY$
BEGIN
IF NEW.deleted IS TRUE THEN
-- delete this entry
DELETE FROM qgep_od.vw_qgep_wastewater_structure
WHERE obj_id = NEW.obj_id;
ELSE
-- insert data into quarantine
INSERT INTO qgep_import.manhole_quarantine
(
obj_id,
identifier,
situation_geometry,
co_shape,
co_diameter,
co_material,
co_positional_accuracy,
co_level,
_depth,
_channel_usage_current,
ma_material,
ma_dimension1,
ma_dimension2,
ws_type,
ma_function,
ss_function,
remark,
wn_bottom_level,
photo1,
photo2,
inlet_3_material,
inlet_3_clear_height,
inlet_3_depth_m,
inlet_4_material,
inlet_4_clear_height,
inlet_4_depth_m,
inlet_5_material,
inlet_5_clear_height,
inlet_5_depth_m,
inlet_6_material,
inlet_6_clear_height,
inlet_6_depth_m,
inlet_7_material,
inlet_7_clear_height,
inlet_7_depth_m,
outlet_1_material,
outlet_1_clear_height,
outlet_1_depth_m,
outlet_2_material,
outlet_2_clear_height,
outlet_2_depth_m
)
VALUES
(
NEW.obj_id,
NEW.identifier,
NEW.situation_geometry,
NEW.co_shape,
NEW.co_diameter,
NEW.co_material,
NEW.co_positional_accuracy,
NEW.co_level,
NEW._depth,
NEW._channel_usage_current,
NEW.ma_material,
NEW.ma_dimension1,
NEW.ma_dimension2,
NEW.ws_type,
NEW.ma_function,
NEW.ss_function,
NEW.remark,
NEW.wn_bottom_level,
NEW.photo1,
NEW.photo2,
NEW.inlet_3_material,
NEW.inlet_3_clear_height,
NEW.inlet_3_depth_m,
NEW.inlet_4_material,
NEW.inlet_4_clear_height,
NEW.inlet_4_depth_m,
NEW.inlet_5_material,
NEW.inlet_5_clear_height,
NEW.inlet_5_depth_m,
NEW.inlet_6_material,
NEW.inlet_6_clear_height,
NEW.inlet_6_depth_m,
NEW.inlet_7_material,
NEW.inlet_7_clear_height,
NEW.inlet_7_depth_m,
NEW.outlet_1_material,
NEW.outlet_1_clear_height,
NEW.outlet_1_depth_m,
NEW.outlet_2_material,
NEW.outlet_2_clear_height,
NEW.outlet_2_depth_m
);
END IF;
RETURN NEW;
END; $BODY$
LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS on_mutation_make_insert_or_delete ON qgep_import.vw_manhole;
CREATE TRIGGER on_mutation_make_insert_or_delete
INSTEAD OF INSERT OR UPDATE
ON qgep_import.vw_manhole
FOR EACH ROW
EXECUTE PROCEDURE qgep_import.vw_manhole_insert_into_quarantine_or_delete();
-- create triggerfunctions and triggers for quarantine table
SELECT set_config('qgep.srid', :SRID::text, false);
DO $DO$
BEGIN
EXECUTE format($TRIGGER$
CREATE OR REPLACE FUNCTION qgep_import.manhole_quarantine_try_structure_update() RETURNS trigger AS $BODY$
DECLARE
multi_situation_geometry geometry(MULTIPOINTZ,%1$s);
BEGIN
multi_situation_geometry = st_collect(NEW.situation_geometry)::geometry(MULTIPOINTZ,%1$s);
-- in case there is a depth, but no refercing value - it should stay in quarantene
IF( NEW._depth IS NOT NULL AND NEW.co_level IS NULL AND NEW.wn_bottom_level IS NULL ) THEN
RAISE EXCEPTION 'No referencing value for calculation with depth';
END IF;
-- qgep_od.wastewater_structure
IF( SELECT TRUE FROM qgep_od.vw_qgep_wastewater_structure WHERE obj_id = NEW.obj_id ) THEN
UPDATE qgep_od.vw_qgep_wastewater_structure SET
identifier = NEW.identifier,
situation_geometry = multi_situation_geometry,
co_shape = NEW.co_shape,
co_diameter = NEW.co_diameter,
co_material = NEW.co_material,
co_positional_accuracy = NEW.co_positional_accuracy,
co_level =
(CASE WHEN NEW.co_level IS NULL AND NEW.wn_bottom_level IS NOT NULL AND NEW._depth IS NOT NULL
THEN NEW.wn_bottom_level + NEW._depth
ELSE NEW.co_level
END),
_depth = NEW._depth,
_channel_usage_current = NEW._channel_usage_current,
ma_material = NEW.ma_material,
ma_dimension1 = NEW.ma_dimension1,
ma_dimension2 = NEW.ma_dimension2,
ws_type = NEW.ws_type,
ma_function = NEW.ma_function,
ss_function = NEW.ss_function,
remark = NEW.remark,
wn_bottom_level =
(CASE WHEN NEW.wn_bottom_level IS NULL AND NEW.co_level IS NOT NULL AND NEW._depth IS NOT NULL
THEN NEW.co_level - NEW._depth
ELSE NEW.wn_bottom_level
END)
WHERE obj_id = NEW.obj_id;
RAISE NOTICE 'Updated row in qgep_od.vw_qgep_wastewater_structure';
ELSE
INSERT INTO qgep_od.vw_qgep_wastewater_structure
(
obj_id,
identifier,
situation_geometry,
co_shape,
co_diameter,
co_material,
co_positional_accuracy,
co_level,
_depth,
_channel_usage_current,
ma_material,
ma_dimension1,
ma_dimension2,
ws_type,
ma_function,
ss_function,
remark,
wn_bottom_level
)
VALUES
(
NEW.obj_id,
NEW.identifier,
multi_situation_geometry,
NEW.co_shape,
NEW.co_diameter,
NEW.co_material,
NEW.co_positional_accuracy,
(CASE WHEN NEW.co_level IS NULL AND NEW.wn_bottom_level IS NOT NULL AND NEW._depth IS NOT NULL
THEN NEW.wn_bottom_level + NEW._depth
ELSE NEW.co_level
END),
NEW._depth,
NEW._channel_usage_current,
NEW.ma_material,
NEW.ma_dimension1,
NEW.ma_dimension2,
NEW.ws_type,
NEW.ma_function,
NEW.ss_function,
NEW.remark,
(CASE WHEN NEW.wn_bottom_level IS NULL AND NEW.co_level IS NOT NULL AND NEW._depth IS NOT NULL
THEN NEW.co_level - NEW._depth
ELSE NEW.wn_bottom_level
END)
);
RAISE NOTICE 'Inserted row in qgep_od.vw_qgep_wastewater_structure';
END IF;
-- photo1 insert
IF (NEW.photo1 IS NOT NULL) THEN
INSERT INTO qgep_od.file
(
object,
identifier
)
VALUES
(
NEW.obj_id,
NEW.photo1
);
RAISE NOTICE 'Inserted row in qgep_od.file';
END IF;
-- photo2 insert
IF (NEW.photo2 IS NOT NULL) THEN
INSERT INTO qgep_od.file
(
object,
identifier
)
VALUES
(
NEW.obj_id,
NEW.photo2
);
RAISE NOTICE 'Inserted row in qgep_od.file';
END IF;
-- set structure okay
UPDATE qgep_import.manhole_quarantine
SET structure_okay = true
WHERE quarantine_serial = NEW.quarantine_serial;
RETURN NEW;
-- catch
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'EXCEPTION: %%', SQLERRM;
RETURN NEW;
END; $BODY$
LANGUAGE plpgsql;
$TRIGGER$, current_setting('qgep.srid'));
END
$DO$;
DROP TRIGGER IF EXISTS after_update_try_structure_update ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_update_try_structure_update
AFTER UPDATE
ON qgep_import.manhole_quarantine
FOR EACH ROW
WHEN ( ( NEW.structure_okay IS NOT TRUE )
AND NOT( OLD.inlet_okay IS NOT TRUE AND NEW.inlet_okay IS TRUE )
AND NOT( OLD.outlet_okay IS NOT TRUE AND NEW.outlet_okay IS TRUE ) )
EXECUTE PROCEDURE qgep_import.manhole_quarantine_try_structure_update();
DROP TRIGGER IF EXISTS after_insert_try_structure_update ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_insert_try_structure_update
AFTER INSERT
ON qgep_import.manhole_quarantine
FOR EACH ROW
EXECUTE PROCEDURE qgep_import.manhole_quarantine_try_structure_update();
-- Some information:
-- 1. new lets 0 - old lets 0 -> do nothing
-- 2. new lets 0 - old lets 1 -> manual deletion needed (or not, depending on if it's on purpose or not)
-- 3. new lets 0 - old lets n -> manual deletion needed (or not, depending on if it's on purpose or not)
-- 4. new lets 1 - old lets 0 -> manual creation needed
-- 5. new lets 1 - old lets 1 -> update let
-- 6. new lets 1 - old lets n -> manual update needed
-- 7. new lets n - old lets 0 -> manual creation needed
-- 8. new lets n - old lets 1 -> manual update needed
-- 9. new lets n - old lets n -> manual update needed
CREATE OR REPLACE FUNCTION qgep_import.manhole_quarantine_try_let_update() RETURNS trigger AS $BODY$
DECLARE
let_kind text;
new_lets integer;
old_lets integer;
BEGIN
let_kind := TG_ARGV[0];
-- count new lets
IF let_kind='inlet' AND ( NEW.inlet_3_material IS NOT NULL OR NEW.inlet_3_depth_m IS NOT NULL OR NEW.inlet_3_clear_height IS NOT NULL )
OR let_kind='outlet' AND ( NEW.outlet_1_material IS NOT NULL OR NEW.outlet_1_depth_m IS NOT NULL OR NEW.outlet_1_clear_height IS NOT NULL ) THEN
IF let_kind='inlet' AND ( NEW.inlet_4_material IS NOT NULL OR NEW.inlet_4_depth_m IS NOT NULL OR NEW.inlet_4_clear_height IS NOT NULL )
OR let_kind='outlet' AND ( NEW.outlet_2_material IS NOT NULL OR NEW.outlet_2_depth_m IS NOT NULL OR NEW.outlet_2_clear_height IS NOT NULL ) THEN
new_lets = 2; -- it's possibly more, but at least > 1
ELSE
new_lets = 1;
END IF;
ELSE
new_lets = 0;
END IF;
-- count old lets
old_lets = ( SELECT COUNT (*)
FROM qgep_od.reach re
LEFT JOIN qgep_od.reach_point rp ON let_kind='inlet' AND rp.obj_id = re.fk_reach_point_to OR let_kind='outlet' AND rp.obj_id = re.fk_reach_point_from
LEFT JOIN qgep_od.wastewater_networkelement wn ON wn.obj_id = rp.fk_wastewater_networkelement
LEFT JOIN qgep_od.vw_qgep_wastewater_structure ws ON ws.obj_id = wn.fk_wastewater_structure
WHERE ws.obj_id = NEW.obj_id );
-- handle inlets
IF ( new_lets > 1 AND old_lets > 0 ) OR old_lets > 1 THEN
-- request for update because new lets are bigger 1 (and old lets not 0 ) or old lets are bigger 1
RAISE NOTICE 'Impossible to assign %s - manual edit needed.', let_kind;
ELSE
IF new_lets = 0 AND old_lets > 0 THEN
-- request for delete because no new lets but old lets
RAISE NOTICE 'No new %s but old ones - manual delete needed.', let_kind;
ELSIF new_lets > 0 AND old_lets = 0 THEN
-- request for create because no old lets but new lets
RAISE NOTICE 'No old %s but new ones - manual create needed.', let_kind;
ELSE
IF new_lets = 1 AND old_lets = 1 THEN
IF let_kind='inlet' THEN
-- update material and dimension on reach
UPDATE qgep_od.reach
SET material = NEW.inlet_3_material,
clear_height = NEW.inlet_3_clear_height
WHERE obj_id = ( SELECT re.obj_id
FROM qgep_od.reach re
LEFT JOIN qgep_od.reach_point rp ON rp.obj_id = re.fk_reach_point_to
LEFT JOIN qgep_od.wastewater_networkelement wn ON wn.obj_id = rp.fk_wastewater_networkelement
LEFT JOIN qgep_od.vw_qgep_wastewater_structure ws ON ws.obj_id = wn.fk_wastewater_structure
WHERE ws.obj_id = NEW.obj_id );
-- update depth_m on reach_point
UPDATE qgep_od.reach_point
SET level = NEW.co_level - NEW.inlet_3_depth_m
WHERE obj_id = ( SELECT rp.obj_id
FROM qgep_od.reach re
LEFT JOIN qgep_od.reach_point rp ON rp.obj_id = re.fk_reach_point_to
LEFT JOIN qgep_od.wastewater_networkelement wn ON wn.obj_id = rp.fk_wastewater_networkelement
LEFT JOIN qgep_od.vw_qgep_wastewater_structure ws ON ws.obj_id = wn.fk_wastewater_structure
WHERE ws.obj_id = NEW.obj_id );
ELSE
-- update material on reach
UPDATE qgep_od.reach
SET material = NEW.outlet_1_material,
clear_height = NEW.outlet_1_clear_height
WHERE obj_id = ( SELECT re.obj_id
FROM qgep_od.reach re
LEFT JOIN qgep_od.reach_point rp ON rp.obj_id = re.fk_reach_point_from
LEFT JOIN qgep_od.wastewater_networkelement wn ON wn.obj_id = rp.fk_wastewater_networkelement
LEFT JOIN qgep_od.vw_qgep_wastewater_structure ws ON ws.obj_id = wn.fk_wastewater_structure
WHERE ws.obj_id = NEW.obj_id );
-- update depth_m on reach_point
UPDATE qgep_od.reach_point
SET level = NEW.co_level - NEW.outlet_1_depth_m
WHERE obj_id = ( SELECT rp.obj_id
FROM qgep_od.reach re
LEFT JOIN qgep_od.reach_point rp ON rp.obj_id = re.fk_reach_point_from
LEFT JOIN qgep_od.wastewater_networkelement wn ON wn.obj_id = rp.fk_wastewater_networkelement
LEFT JOIN qgep_od.vw_qgep_wastewater_structure ws ON ws.obj_id = wn.fk_wastewater_structure
WHERE ws.obj_id = NEW.obj_id );
END IF;
RAISE NOTICE '%s updated', let_kind;
ELSE
-- do nothing
RAISE NOTICE 'No %s - nothing to do', let_kind;
END IF;
IF let_kind='inlet' THEN
-- set inlet okay
UPDATE qgep_import.manhole_quarantine
SET inlet_okay = true
WHERE quarantine_serial = NEW.quarantine_serial;
ELSE
-- set outlet okay
UPDATE qgep_import.manhole_quarantine
SET outlet_okay = true
WHERE quarantine_serial = NEW.quarantine_serial;
END IF;
END IF;
END IF;
RETURN NEW;
-- catch
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'EXCEPTION: %', SQLERRM;
RETURN NEW;
END; $BODY$
LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS after_update_try_inlet_update ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_update_try_inlet_update
AFTER UPDATE
ON qgep_import.manhole_quarantine
FOR EACH ROW
WHEN ( ( NEW.inlet_okay IS NOT TRUE )
AND NOT( OLD.outlet_okay IS NOT TRUE AND NEW.outlet_okay IS TRUE )
AND NOT( OLD.structure_okay IS NOT TRUE AND NEW.structure_okay IS TRUE ) )
EXECUTE PROCEDURE qgep_import.manhole_quarantine_try_let_update( 'inlet' );
DROP TRIGGER IF EXISTS after_insert_try_inlet_update ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_insert_try_inlet_update
AFTER INSERT
ON qgep_import.manhole_quarantine
FOR EACH ROW
EXECUTE PROCEDURE qgep_import.manhole_quarantine_try_let_update( 'inlet' );
DROP TRIGGER IF EXISTS after_update_try_outlet_update ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_update_try_outlet_update
AFTER UPDATE
ON qgep_import.manhole_quarantine
FOR EACH ROW
WHEN ( ( NEW.outlet_okay IS NOT TRUE )
AND NOT( OLD.inlet_okay IS NOT TRUE AND NEW.inlet_okay IS TRUE )
AND NOT( OLD.structure_okay IS NOT TRUE AND NEW.structure_okay IS TRUE ) )
EXECUTE PROCEDURE qgep_import.manhole_quarantine_try_let_update( 'outlet' );
DROP TRIGGER IF EXISTS after_insert_try_outlet_update ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_insert_try_outlet_update
AFTER INSERT
ON qgep_import.manhole_quarantine
FOR EACH ROW
EXECUTE PROCEDURE qgep_import.manhole_quarantine_try_let_update( 'outlet' );
CREATE OR REPLACE FUNCTION qgep_import.manhole_quarantine_delete_entry() RETURNS trigger AS $BODY$
BEGIN
DELETE FROM qgep_import.manhole_quarantine
WHERE quarantine_serial = NEW.quarantine_serial;
RAISE NOTICE 'Deleted row in qgep_import.manhole_quarantine';
RETURN NEW;
END; $BODY$
LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS after_mutation_delete_when_okay ON qgep_import.manhole_quarantine;
CREATE TRIGGER after_mutation_delete_when_okay
AFTER INSERT OR UPDATE
ON qgep_import.manhole_quarantine
FOR EACH ROW
WHEN ( NEW.structure_okay IS TRUE AND NEW.inlet_okay IS TRUE AND NEW.outlet_okay IS TRUE )
EXECUTE PROCEDURE qgep_import.manhole_quarantine_delete_entry();