Sfoglia il codice sorgente

Don't ignore errors when getting DB schema version

It probably never errors because connection errors would break the
create table call, but this way is safer.
Tulir Asokan 3 anni fa
parent
commit
ccfd7819c3
1 ha cambiato i file con 4 aggiunte e 3 eliminazioni
  1. 4 3
      database/upgrades/upgrades.go

+ 4 - 3
database/upgrades/upgrades.go

@@ -2,6 +2,7 @@ package upgrades
 
 import (
 	"database/sql"
+	"errors"
 	"fmt"
 	"strings"
 
@@ -52,9 +53,9 @@ func GetVersion(db *sql.DB) (int, error) {
 	}
 
 	version := 0
-	row := db.QueryRow("SELECT version FROM version LIMIT 1")
-	if row != nil {
-		_ = row.Scan(&version)
+	err = db.QueryRow("SELECT version FROM version LIMIT 1").Scan(&version)
+	if err != nil && !errors.Is(err, sql.ErrNoRows) {
+		return -1, err
 	}
 	return version, nil
 }