diff schema/gemma.sql @ 4067:0ba3fc89b499 historization_ng

Adapted references to bottlenecks from fairway_availability in DB schema.
author Sascha Wilde <wilde@intevation.de>
date Thu, 25 Jul 2019 12:33:19 +0200
parents 8c6bc85db711
children 76482935b6e5
line wrap: on
line diff
--- a/schema/gemma.sql	Wed Jul 24 18:55:09 2019 +0200
+++ b/schema/gemma.sql	Thu Jul 25 12:33:19 2019 +0200
@@ -724,7 +724,7 @@
     CREATE TABLE fairway_availability (
         id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
         position_code char(2) REFERENCES position_codes,
-        bottleneck_id int NOT NULL REFERENCES bottlenecks(id),
+        bottleneck_id varchar NOT NULL,
         surdat date NOT NULL,
         UNIQUE (bottleneck_id, surdat),
         -- additional_data xml -- Currently not relevant for GEMMA
@@ -735,6 +735,18 @@
     CREATE TRIGGER fairway_availability_date_info
         BEFORE UPDATE ON fairway_availability
         FOR EACH ROW EXECUTE PROCEDURE update_date_info()
+    -- FIXME: From the DRC it is unclear what the exact semantics of
+    --   surdat and Date_Info ar unclear.  Currently we assume that
+    --   (fk_bn_fid,surdat) has to be unique, but that might be false.
+    --   Anyway, I will date_info here to check for an matching
+    --   reference gauge at the bottleneck.  The reason for this
+    --   decision is purely practical (and might be semantically
+    --   disputable: the bottleneck data in the demo system is not old
+    --   enough to cover rthe surdat times...
+    CREATE CONSTRAINT TRIGGER fairway_availability_referenced_bottleneck
+        AFTER INSERT OR UPDATE OF bottleneck_id ON fairway_availability
+        FOR EACH ROW
+        EXECUTE FUNCTION check_valid_bottleneck_ts('bottleneck_id','date_info')
 
     CREATE TABLE fa_reference_values (
         fairway_availability_id int NOT NULL REFERENCES fairway_availability,