# HG changeset patch # User Tom Gottfried # Date 1579022691 -3600 # Node ID 9f799077a3e630b4c4e7b6856cba4dd628bd0050 # Parent 8eb36d0d5bdfd31fcfb81e6a7eb73a4cba362cf5 Prevent importing non-distinct fairway marks diff -r 8eb36d0d5bdf -r 9f799077a3e6 pkg/imports/fm.go --- a/pkg/imports/fm.go Tue Jan 14 15:01:42 2020 +0100 +++ b/pkg/imports/fm.go Tue Jan 14 18:24:51 2020 +0100 @@ -135,6 +135,13 @@ WHERE pg_has_role('sys_admin', 'MEMBER') OR ST_Intersects((select a from a), ST_Transform(newfm, (select ST_SRID(a) from a))) +ON CONFLICT ( + CAST((0, geom, + datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom, + scamin, picrep, txtdsc, sordat, sorind, colour, colpat, condtn, + bcnshp, catlam, dirimp) AS waterway.fairway_marks) + ) + DO NOTHING RETURNING id ` ) @@ -197,7 +204,7 @@ unsupported = stringCounter{} missingProperties int badProperties int - outside int + outsideOrDup int features int ) @@ -287,7 +294,7 @@ }) switch { case err == sql.ErrNoRows: - outside++ + outsideOrDup++ // ignore -> filtered by responsibility_areas case err != nil: feedback.Error(pgxutils.ReadableError{Err: err}.Error()) @@ -315,13 +322,14 @@ feedback.Warn("Unsupported types found: %s", unsupported) } - if outside > 0 { - feedback.Info("Features outside responsibility area: %d", outside) + if outsideOrDup > 0 { + feedback.Info( + "Features outside responsibility area and duplicates: %d", + outsideOrDup) } if features == 0 { - err := errors.New("no features found") - feedback.Error("%v", err) + err := errors.New("no valid new features found") return nil, err } diff -r 8eb36d0d5bdf -r 9f799077a3e6 schema/gemma.sql --- a/schema/gemma.sql Tue Jan 14 15:01:42 2020 +0100 +++ b/schema/gemma.sql Tue Jan 14 18:24:51 2020 +0100 @@ -864,6 +864,14 @@ catlam int, dirimp smallint REFERENCES dirimps ) + -- Prevent identical entries using composite type comparison + -- (i.e. considering two NULL values in a field equal): + CREATE UNIQUE INDEX fairway_marks_distinct_rows ON fairway_marks + ((CAST((0, geom, + datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom, + scamin, picrep, txtdsc, sordat, sorind, colour, colpat, condtn, + bcnshp, catlam, dirimp) AS fairway_marks) + )) ;