diff schema/tap_tests_data.sql @ 3302:ec6163c6687d

'Historicise' gauges on import Gauge data sets will be updated or a new version will be inserted depending on temporal validity and a timestamp marking the last update in the RIS-Index of a data set. The trigger on date_info is removed because the value is actually an attribut coming from the RIS-Index. Gauge measurements and predictions are associated to the version with matching temporal validity. Bottlenecks are always associated to the actual version of the gauge, although this might change as soon as bottlenecks are 'historicised', too.
author Tom Gottfried <tom@intevation.de>
date Thu, 16 May 2019 18:41:43 +0200
parents a2127495093e
children 02951a62e8c6
line wrap: on
line diff
--- a/schema/tap_tests_data.sql	Thu May 16 17:22:33 2019 +0200
+++ b/schema/tap_tests_data.sql	Thu May 16 18:41:43 2019 +0200
@@ -37,22 +37,30 @@
 
 INSERT INTO limiting_factors VALUES ('depth'), ('width');
 
-INSERT INTO waterway.gauges (
-    location, objname, geom, zero_point, source_organization)
+WITH
+gs AS (
+    INSERT INTO waterway.gauges (
+        location,
+        validity,
+        objname,
+        geom,
+        zero_point,
+        date_info,
+        source_organization,
+        lastupdate)
     VALUES (
         ('AT', 'XXX', '00001', 'G0001', 1)::isrs,
+        tstzrange(current_timestamp - '1 day'::interval, current_timestamp),
         'testgauge',
         ST_geomfromtext('POINT(0 0)', 4326),
         0,
-        'testorganization'
-    );
-
-INSERT INTO waterway.bottlenecks (
-    bottleneck_id, fk_g_fid, stretch, area, rb, lb, responsible_country,
-    revisiting_time, limiting, source_organization, staging_done)
+        current_timestamp,
+        'testorganization',
+        current_timestamp)
+    RETURNING location, validity),
+bns AS (
     VALUES (
         'testbottleneck1',
-        ('AT', 'XXX', '00001', 'G0001', 1)::isrs,
         isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs,
             ('AT', 'XXX', '00001', '00000', 2)::isrs),
         ST_geomfromtext('MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 4326),
@@ -60,13 +68,17 @@
         1, 'depth', 'testorganization', false
     ), (
         'testbottleneck2',
-        ('AT', 'XXX', '00001', 'G0001', 1)::isrs,
         isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs,
             ('AT', 'XXX', '00001', '00000', 2)::isrs),
         ST_geomfromtext('MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 4326),
         'AT', 'AT', 'AT',
         1, 'depth', 'testorganization', true
-    );
+    ))
+INSERT INTO waterway.bottlenecks (
+    gauge_location, gauge_validity,
+    bottleneck_id, stretch, area, rb, lb, responsible_country,
+    revisiting_time, limiting, source_organization, staging_done)
+    SELECT * FROM gs, bns;
 
 INSERT INTO waterway.distance_marks_virtual VALUES (
     ('AT', 'XXX', '00001', '00000', 0)::isrs,