changeset 4085:c0642c1c0ff8 historization_ng

Be more permissive during afd data migration. Add the constraint trigger _after_ migrating old data.
author Sascha Wilde <wilde@intevation.de>
date Thu, 25 Jul 2019 17:06:19 +0200
parents c9bef8c27685
children 30a567b1cc2e
files schema/updates/1100/02.remove_bottleneck_validity_refs.sql
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/schema/updates/1100/02.remove_bottleneck_validity_refs.sql	Thu Jul 25 16:31:18 2019 +0200
+++ b/schema/updates/1100/02.remove_bottleneck_validity_refs.sql	Thu Jul 25 17:06:19 2019 +0200
@@ -161,6 +161,14 @@
       RENAME COLUMN bottleneck_id TO old_bnid;
   ALTER TABLE waterway.fairway_availability
       ADD COLUMN bottleneck_id varchar;
+
+  -- Migrate existing data: Let's be ultra permissive and make the
+  -- migration _before adding the constraint triggger.
+  UPDATE waterway.fairway_availability AS fwa
+      SET bottleneck_id = b.bottleneck_id
+      FROM waterway.bottlenecks b
+      WHERE b.id = fwa.old_bnid;
+
   -- Set constraint trigger to make sure a matching BN exists:
   --
   -- FIXME: From the DRC it is unclear what the exact semantics of
@@ -175,12 +183,6 @@
       AFTER INSERT OR UPDATE OF bottleneck_id ON waterway.fairway_availability
       FOR EACH ROW
       EXECUTE FUNCTION check_valid_bottleneck_ts('bottleneck_id','date_info');
-
-  -- Migrate existing data:
-  UPDATE waterway.fairway_availability AS fwa
-      SET bottleneck_id = b.bottleneck_id
-      FROM waterway.bottlenecks b
-      WHERE b.id = fwa.old_bnid;
   -- Set NOT NULL constraint for new column
   ALTER TABLE waterway.fairway_availability
       ALTER COLUMN bottleneck_id SET NOT NULL;