Skip to content

Commit

Permalink
reorder table update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed Feb 22, 2024
1 parent 05d8ffe commit 57f8692
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,22 @@ func updateTables() error {
_, err := db.Exec(`
ALTER TABLE dogs ADD COLUMN grouping INTEGER;
`)
if err == nil || strings.Contains(err.Error(), "duplicate column name") {
return nil
if err != nil && !strings.Contains(err.Error(), "duplicate column name") {
return fmt.Errorf("error updating dogs table: %v", err)
}

// Set default value for grouping
_, err = db.Exec(`
UPDATE dogs SET grouping = 0 where grouping is null;
UPDATE dogs SET grouping = 0 WHERE grouping IS NULL
`)
if err != nil {
return fmt.Errorf("error updating dogs table: %v", err)
}

return fmt.Errorf("error updating dogs table: %v", err)
return nil
}

func getDogs() ([]Dog, error) {
rows, err := db.Query("SELECT * FROM dogs group by grouping, id")
rows, err := db.Query("SELECT * FROM dogs group by grouping, id;")
if err != nil {
return nil, fmt.Errorf("error getting dogs: %v", err)
}
Expand Down

0 comments on commit 57f8692

Please sign in to comment.