Mercurial > gemma
changeset 2072:b4d8d320feab
Waterway profile import: Added import stub and changed database.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 30 Jan 2019 17:11:10 +0100 |
parents | 5c6816780bf5 |
children | e6dccc7a3ea1 |
files | pkg/imports/wp.go schema/gemma.sql |
diffstat | 2 files changed, 86 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/imports/wp.go Wed Jan 30 17:11:10 2019 +0100 @@ -0,0 +1,78 @@ +// This is Free Software under GNU Affero General Public License v >= 3.0 +// without warranty, see README.md and license for details. +// +// SPDX-License-Identifier: AGPL-3.0-or-later +// License-Filename: LICENSES/AGPL-3.0.txt +// +// Copyright (C) 2018 by via donau +// – Österreichische Wasserstraßen-Gesellschaft mbH +// Software engineering by Intevation GmbH +// +// Author(s): +// * Sascha L. Teichmann <sascha.teichmann@intevation.de> + +package imports + +import ( + "context" + "database/sql" + "errors" + "os" + + "gemma.intevation.de/gemma/pkg/common" +) + +type WaterwayProfiles struct { + Dir string `json:"dir"` +} + +const WPJobKind JobKind = "wp" + +type wpJobCreator struct{} + +func init() { + RegisterJobCreator(WPJobKind, wpJobCreator{}) +} + +func (wpJobCreator) Create(_ JobKind, data string) (Job, error) { + wp := new(WaterwayProfiles) + if err := common.FromJSONString(data, wp); err != nil { + return nil, err + } + return wp, nil +} + +func (wpJobCreator) AutoAccept() bool { return false } + +func (wpJobCreator) Description() string { + return "waterway profiles" +} + +func (wpJobCreator) Depends() []string { + return []string{ + "waterway_profiles", + } +} + +func (wpJobCreator) StageDone( + ctx context.Context, + tx *sql.Tx, + id int64, +) error { + // TODO: Implement me! + return nil +} + +func (wp *WaterwayProfiles) CleanUp() error { + return os.RemoveAll(wp.Dir) +} + +func (wp *WaterwayProfiles) Do( + ctx context.Context, + importID int64, + conn *sql.Conn, + feedback Feedback, +) (interface{}, error) { + // TODO: Implement me! + return nil, errors.New("Not implemented, yet!") +}
--- a/schema/gemma.sql Wed Jan 30 15:45:33 2019 +0100 +++ b/schema/gemma.sql Wed Jan 30 17:11:10 2019 +0100 @@ -394,21 +394,22 @@ FOR EACH ROW EXECUTE PROCEDURE update_date_info() CREATE TABLE waterway_profiles ( + id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, location isrs NOT NULL, validity tstzrange, EXCLUDE USING GIST (validity WITH &&), - PRIMARY KEY (location, validity), - lnwl smallint, - mwl smallint, - hnwl smallint, - fe30 smallint, - fe100 smallint, + lnwl double precision, + mwl double precision, + hnwl double precision, + fe30 double precision, + fe100 double precision, -- XXX: further normalise using reference_water_levels? CHECK(COALESCE(lnwl, mwl, hnwl, fe30, fe100) IS NULL OR validity IS NOT NULL), date_info timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, source_organization varchar NOT NULL, - staging_done boolean NOT NULL DEFAULT false + staging_done boolean NOT NULL DEFAULT false, + UNIQUE (location, validity, staging_done) ) CREATE TRIGGER waterway_profiles_date_info BEFORE UPDATE ON waterway_profiles