# HG changeset patch # User Tom Gottfried # Date 1559141006 -7200 # Node ID ba0339118d9c67826e30085aa88e736366039107 # Parent b9e331c1e6163dcbe4140754dc441c9bc5d652d7 Improve validation of gauge temporal validity The current version of a gauge should always have a validity represented by a non-empty time range. Thus, do not accept empty time ranges on input. Nevertheless, continue to accept storing empty time ranges (no CHECK constraint), because a new version with equal start date but longer validity might still cause the previous version to get an empty time range. In passing, add a missing NOT NULL constraint: if both start and end date are omitted, the range will be unbounded, but it should never be NULL. diff -r b9e331c1e616 -r ba0339118d9c pkg/imports/wg.go --- a/pkg/imports/wg.go Wed May 29 16:00:28 2019 +0200 +++ b/pkg/imports/wg.go Wed May 29 16:43:26 2019 +0200 @@ -235,10 +235,10 @@ gauges = append(gauges, isrs) feedback.Info("Processing %s", code) - // We need a valid time range to identify gauge versions in DB + // We need a valid, non-empty time range to identify gauge versions if dr.Enddate != nil && dr.Startdate != nil && - time.Time(*dr.Enddate).Before(time.Time(*dr.Startdate)) { - feedback.Warn("End date before start date") + !time.Time(*dr.Enddate).After(time.Time(*dr.Startdate)) { + feedback.Warn("End date not after start date") unchanged++ continue } diff -r b9e331c1e616 -r ba0339118d9c schema/gemma.sql --- a/schema/gemma.sql Wed May 29 16:00:28 2019 +0200 +++ b/schema/gemma.sql Wed May 29 16:43:26 2019 +0200 @@ -280,7 +280,7 @@ geom geography(POINT, 4326) NOT NULL, applicability_from_km int8, applicability_to_km int8, - validity tstzrange, + validity tstzrange NOT NULL, zero_point double precision NOT NULL, geodref varchar, date_info timestamp with time zone NOT NULL,