Mercurial > gemma
comparison pkg/imports/bn.go @ 4133:eb08fbe33074
Fixed bn-import: never write tracking info to the db if import fails.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 01 Aug 2019 19:21:43 +0200 |
parents | 980f12d3c766 |
children | 9864d682ab47 |
comparison
equal
deleted
inserted
replaced
4132:ec8438712447 | 4133:eb08fbe33074 |
---|---|
521 // We handle it gracefully anyway, but warn. | 521 // We handle it gracefully anyway, but warn. |
522 feedback.Warn("More than one Bottelneck '%s' "+ | 522 feedback.Warn("More than one Bottelneck '%s' "+ |
523 "with intersecting validity already exists: "+ | 523 "with intersecting validity already exists: "+ |
524 "REPLACING all of them!", bn.Bottleneck_id) | 524 "REPLACING all of them!", bn.Bottleneck_id) |
525 } | 525 } |
526 | 526 // We write the actual tracking information for deletion of superseded |
527 for _, oldID := range oldBnIds { | 527 // bottlenecks later to the databs -- AFTER the new bottleneck was |
528 // It is possible, that two new bottlenecks intersect with the | 528 // created successfully. That way, we don't change the database, when |
529 // same old noe, therefor we have to handle duplicates in | 529 // an error arises during inserting the new data. |
530 // oldBnIds. | |
531 if !seenOldBnIds[oldID] { | |
532 if _, err := tx.StmtContext(ctx, bs.track).ExecContext( | |
533 ctx, importID, "waterway.bottlenecks", oldID, true, | |
534 ); err != nil { | |
535 return err | |
536 } | |
537 seenOldBnIds[oldID] = true | |
538 } | |
539 } | |
540 | 530 |
541 var bnIds []int64 | 531 var bnIds []int64 |
542 // Add new BN data: | 532 // Add new BN data: |
543 savepoint := Savepoint(ctx, tx, "insert_bottlenck") | 533 savepoint := Savepoint(ctx, tx, "insert_bottlenck") |
544 | 534 |
596 if err != nil { | 586 if err != nil { |
597 feedback.Warn(pgxutils.ReadableError{err}.Error()) | 587 feedback.Warn(pgxutils.ReadableError{err}.Error()) |
598 return nil | 588 return nil |
599 } | 589 } |
600 | 590 |
601 // Only add new BN data to tracking for staging review. | 591 // Now that adding BNs to staging was successful, write import tracking |
592 // information to database: | |
593 for _, oldID := range oldBnIds { | |
594 // It is possible, that two new bottlenecks intersect with the | |
595 // same old noe, therefor we have to handle duplicates in | |
596 // oldBnIds. | |
597 if !seenOldBnIds[oldID] { | |
598 if _, err := tx.StmtContext(ctx, bs.track).ExecContext( | |
599 ctx, importID, "waterway.bottlenecks", oldID, true, | |
600 ); err != nil { | |
601 return err | |
602 } | |
603 seenOldBnIds[oldID] = true | |
604 } | |
605 } | |
602 for _, nid := range bnIds { | 606 for _, nid := range bnIds { |
603 if _, err := tx.StmtContext(ctx, bs.track).ExecContext( | 607 if _, err := tx.StmtContext(ctx, bs.track).ExecContext( |
604 ctx, importID, "waterway.bottlenecks", nid, false, | 608 ctx, importID, "waterway.bottlenecks", nid, false, |
605 ); err != nil { | 609 ); err != nil { |
606 return err | 610 return err |