comparison schema/gemma.sql @ 3746:433bad131e5c

Added check trigger to sounding results to ensure they intersect the bn-area.
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Jun 2019 16:13:05 +0200
parents db87f34805fb
children ad67e4286d65
comparison
equal deleted inserted replaced
3745:ae79c9546908 3746:433bad131e5c
176 RETURN NULL; -- ignored 176 RETURN NULL; -- ignored
177 END; 177 END;
178 $$ 178 $$
179 LANGUAGE plpgsql; 179 LANGUAGE plpgsql;
180 180
181 -- Constraint trigger: sounding Results must intersect with the area
182 -- of the bottleneck they belong to.
183 CREATE OR REPLACE FUNCTION check_sr_in_bn_area() RETURNS trigger
184 LANGUAGE plpgsql
185 AS $$
186 BEGIN
187 IF NOT st_intersects((SELECT area
188 FROM waterway.bottlenecks
189 WHERE (bottleneck_id, validity)
190 =(NEW.bottleneck_id, NEW.bottleneck_validity)),
191 NEW.area)
192 THEN
193 RAISE EXCEPTION
194 'new row for relation "%" violates constraint trigger "%"',
195 TG_TABLE_NAME, TG_NAME
196 USING
197 DETAIL = 'Failing row area has no intersection with bottleneck.',
198 ERRCODE = 23514,
199 SCHEMA = TG_TABLE_SCHEMA,
200 TABLE = TG_TABLE_NAME,
201 CONSTRAINT = TG_NAME;
202 END IF;
203 RETURN NEW;
204 END;
205 $$;
206
207
181 -- 208 --
182 -- GEMMA data 209 -- GEMMA data
183 -- 210 --
184 211
185 -- Namespace not to be accessed directly by any user 212 -- Namespace not to be accessed directly by any user
661 depth_reference varchar NOT NULL, -- REFERENCES depth_references, 688 depth_reference varchar NOT NULL, -- REFERENCES depth_references,
662 octree_checksum varchar, 689 octree_checksum varchar,
663 octree_index bytea, 690 octree_index bytea,
664 staging_done boolean NOT NULL DEFAULT false 691 staging_done boolean NOT NULL DEFAULT false
665 ) 692 )
693 CREATE CONSTRAINT TRIGGER sounding_results_in_bn_area
694 AFTER INSERT OR UPDATE ON sounding_results
695 FOR EACH ROW EXECUTE FUNCTION check_sr_in_bn_area();
666 696
667 CREATE TABLE sounding_results_contour_lines ( 697 CREATE TABLE sounding_results_contour_lines (
668 sounding_result_id int NOT NULL REFERENCES sounding_results 698 sounding_result_id int NOT NULL REFERENCES sounding_results
669 ON DELETE CASCADE, 699 ON DELETE CASCADE,
670 height numeric NOT NULL, 700 height numeric NOT NULL,