Rework primary keys in the match list scouting database
We don't need a separate ID for the rows in the match list table. We
really just care about a unique combination of `MatchNumber`, `Round`,
and `CompLevel`.
This will make it easier to update an existing match list. We
currently don't support this.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I7d42dab7695cfee4844bbb7660ed820bb083b199
diff --git a/scouting/db/db.go b/scouting/db/db.go
index 6a12a67..99301f2 100644
--- a/scouting/db/db.go
+++ b/scouting/db/db.go
@@ -67,7 +67,6 @@
}
statement, err := database.Prepare("CREATE TABLE IF NOT EXISTS matches (" +
- "id SERIAL PRIMARY KEY, " +
"MatchNumber INTEGER, " +
"Round INTEGER, " +
"CompLevel VARCHAR, " +
@@ -76,7 +75,8 @@
"R3 INTEGER, " +
"B1 INTEGER, " +
"B2 INTEGER, " +
- "B3 INTEGER)")
+ "B3 INTEGER, " +
+ "PRIMARY KEY (MatchNumber, Round, CompLevel))")
if err != nil {
database.Close()
return nil, errors.New(fmt.Sprint("Failed to prepare matches table creation: ", err))
@@ -327,8 +327,7 @@
matches := make([]Match, 0)
for rows.Next() {
var match Match
- var id int
- err := rows.Scan(&id, &match.MatchNumber, &match.Round, &match.CompLevel,
+ err := rows.Scan(&match.MatchNumber, &match.Round, &match.CompLevel,
&match.R1, &match.R2, &match.R3, &match.B1, &match.B2, &match.B3)
if err != nil {
return nil, errors.New(fmt.Sprint("Failed to scan from matches: ", err))
@@ -400,8 +399,7 @@
var matches []Match
for rows.Next() {
var match Match
- var id int
- err = rows.Scan(&id, &match.MatchNumber, &match.Round, &match.CompLevel,
+ err = rows.Scan(&match.MatchNumber, &match.Round, &match.CompLevel,
&match.R1, &match.R2, &match.R3, &match.B1, &match.B2, &match.B3)
if err != nil {
return nil, errors.New(fmt.Sprint("Failed to scan from matches: ", err))