Mercurial > gemma
changeset 2318:06c4e57435f1
Warn on import of unknown reference level codes
According to the RIS-Index encoding guide, reference level codes
should be in line with the NtS reference_code table. Amend also
the comment in the schema definition to reflect the 'should', which
is not 'shall'.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 18 Feb 2019 19:38:48 +0100 |
parents | 8a8680e70d2e |
children | 478cc0d26d33 |
files | pkg/imports/wg.go schema/gemma.sql |
diffstat | 2 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/wg.go Mon Feb 18 18:45:12 2019 +0100 +++ b/pkg/imports/wg.go Mon Feb 18 19:38:48 2019 +0100 @@ -4,12 +4,13 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // -// Copyright (C) 2018 by via donau +// Copyright (C) 2018, 2019 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> +// * Tom Gottfried <tom.gottfried@intevation.de> package imports @@ -113,6 +114,9 @@ date_info = $14, source_organization = $15 ` + isNtSDepthRefSQL = ` +SELECT EXISTS(SELECT 1 FROM depth_references WHERE depth_reference = $1)` + insertReferenceWaterLevelsSQL = ` INSERT INTO waterway.gauges_reference_water_levels ( gauge_id, @@ -285,6 +289,12 @@ } defer insertWaterLevelStmt.Close() + isNtSDepthRefStmt, err := tx.PrepareContext(ctx, isNtSDepthRefSQL) + if err != nil { + return nil, err + } + defer isNtSDepthRefStmt.Close() + // insert/update the gauges for i := range news { ic := &news[i] @@ -396,6 +406,22 @@ if *wl.level == nil || *wl.value == nil { continue } + + var isNtSDepthRef bool + if err := isNtSDepthRefStmt.QueryRowContext( + ctx, + string(**wl.level), + ).Scan( + &isNtSDepthRef, + ); err != nil { + return nil, err + } + if !isNtSDepthRef { + feedback.Warn( + "Reference level code '%s' is not in line with the NtS reference_code table", + string(**wl.level)) + } + if _, err := insertWaterLevelStmt.ExecContext( ctx, ic.code.CountryCode,
--- a/schema/gemma.sql Mon Feb 18 18:45:12 2019 +0100 +++ b/schema/gemma.sql Mon Feb 18 19:38:48 2019 +0100 @@ -251,8 +251,8 @@ CREATE TABLE gauges_reference_water_levels ( gauge_id isrs NOT NULL REFERENCES gauges, - -- Omit foreign key constraint to be able to store not standards - -- (RIS, NtS) compliant names, too: + -- Omit foreign key constraint to be able to store not NtS-compliant + -- names, too: depth_reference varchar NOT NULL, -- REFERENCES depth_references, PRIMARY KEY (gauge_id, depth_reference), value int NOT NULL