# HG changeset patch # User Sascha L. Teichmann # Date 1554907470 -7200 # Node ID b3c3c5b5b7c1a7a6e37c1812e83745ce2350fb04 # Parent adc8e9ccf706ef5395ccb1aef9ce15673cbcdc92 Bottleneck import: Import riverbed materials, too. diff -r adc8e9ccf706 -r b3c3c5b5b7c1 pkg/imports/bn.go --- a/pkg/imports/bn.go Wed Apr 10 16:04:40 2019 +0200 +++ b/pkg/imports/bn.go Wed Apr 10 16:44:30 2019 +0200 @@ -81,6 +81,15 @@ $13 ) RETURNING id` + + insertBottleneckMaterialSQL = ` +INSERT INTO waterway.bottlenecks_riverbed_materials ( + bottleneck_id, + riverbed +) VALUES ( + $1, + $2 +)` ) type bnJobCreator struct{} @@ -187,7 +196,7 @@ feedback.Info("Found %d bottlenecks for import", len(bns)) - var hasStmt, insertStmt, trackStmt *sql.Stmt + var hasStmt, insertStmt, insertMaterialStmt, trackStmt *sql.Stmt for _, x := range []struct { sql string @@ -195,6 +204,7 @@ }{ {hasBottleneckSQL, &hasStmt}, {insertBottleneckSQL, &insertStmt}, + {insertBottleneckMaterialSQL, &insertMaterialStmt}, {trackImportSQL, &trackStmt}, } { var err error @@ -211,7 +221,7 @@ for _, bn := range bns { if err := storeBottleneck( ctx, importID, conn, feedback, bn, &nids, tolerance, - hasStmt, insertStmt, trackStmt); err != nil { + hasStmt, insertStmt, insertMaterialStmt, trackStmt); err != nil { return nil, err } } @@ -237,7 +247,7 @@ bn *ifbn.BottleNeckType, nids *[]string, tolerance float64, - hasStmt, insertStmt, trackStmt *sql.Stmt, + hasStmt, insertStmt, insertMaterialStmt, trackStmt *sql.Stmt, ) error { tx, err := conn.BeginTx(ctx, nil) @@ -295,6 +305,21 @@ return nil } + if bn.Riverbed != nil { + for _, material := range bn.Riverbed.Material { + if material != nil { + mat := string(*material) + if _, err := tx.Stmt(insertMaterialStmt).ExecContext( + ctx, nid, material); err != nil { + feedback.Warn( + "Failed to insert riverbed material '%s' for bottleneck '%s'.", + mat, bn.OBJNAM) + feedback.Warn(handleError(err).Error()) + } + } + } + } + if _, err := tx.Stmt(trackStmt).ExecContext( ctx, importID, "waterway.bottlenecks", nid, ); err != nil { diff -r adc8e9ccf706 -r b3c3c5b5b7c1 schema/gemma.sql --- a/schema/gemma.sql Wed Apr 10 16:04:40 2019 +0200 +++ b/schema/gemma.sql Wed Apr 10 16:44:30 2019 +0200 @@ -547,7 +547,8 @@ FOR EACH ROW EXECUTE PROCEDURE update_date_info() CREATE TABLE bottlenecks_riverbed_materials ( - bottleneck_id int NOT NULL REFERENCES bottlenecks(id), + bottleneck_id int NOT NULL REFERENCES bottlenecks(id) + ON DELETE CASCADE, riverbed varchar NOT NULL REFERENCES riverbed_materials, -- XXX: should be 'natsur' according to IENC Encoding Guide M.4.3 PRIMARY KEY (bottleneck_id, riverbed)