Skip to content

Commit

Permalink
Issue #4: remove IDs when importing
Browse files Browse the repository at this point in the history
  • Loading branch information
zupzup committed Jun 20, 2017
1 parent a9e9756 commit 70b7a26
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions datasource/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (ds *BoltDataSource) RemoveEntry(entryDate string, id int) error {
// Import imports the given data to the database, overwriting the previous
// data
func (ds *BoltDataSource) Import(data *model.ImpEx) error {
var zeroID int
err := ds.SetConfig(data.Config)
if err != nil {
return fmt.Errorf("could not replace config, %v", err)
Expand All @@ -179,6 +180,7 @@ func (ds *BoltDataSource) Import(data *model.ImpEx) error {
return fmt.Errorf("could not remove weights, %v", err)
}
for _, weight := range data.Weights {
weight.ID = zeroID
err = ds.DB.Save(&weight)
if err != nil {
return fmt.Errorf("could not insert/update weight with id %d", weight.ID)
Expand All @@ -189,6 +191,7 @@ func (ds *BoltDataSource) Import(data *model.ImpEx) error {
return fmt.Errorf("could not remove entries, %v", err)
}
for _, entry := range data.Entries {
entry.ID = zeroID
err = ds.DB.Save(&entry)
if err != nil {
return fmt.Errorf("could not insert/update entry with id %d", entry.ID)
Expand Down

0 comments on commit 70b7a26

Please sign in to comment.