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))
diff --git a/scouting/webserver/requests/debug/cli/cli_test.py b/scouting/webserver/requests/debug/cli/cli_test.py
index 5b0c749..bd1b13d 100644
--- a/scouting/webserver/requests/debug/cli/cli_test.py
+++ b/scouting/webserver/requests/debug/cli/cli_test.py
@@ -52,7 +52,7 @@
"event_code": event_code,
})
exit_code, stdout, stderr = run_debug_cli(["-refreshMatchList", json_path])
- self.assertEqual(exit_code, 0, stderr)
+ self.assertEqual(exit_code, 0, f"{year}{event_code}: {stderr}")
self.assertIn("(refresh_match_list_response.RefreshMatchListResponseT)", stdout)
def test_submit_and_request_data_scouting(self):
diff --git a/scouting/webserver/requests/requests.go b/scouting/webserver/requests/requests.go
index d67f5e9..8132c3d 100644
--- a/scouting/webserver/requests/requests.go
+++ b/scouting/webserver/requests/requests.go
@@ -391,15 +391,14 @@
// Add the match to the database.
err = handler.db.AddToMatch(db.Match{
MatchNumber: int32(match.MatchNumber),
- // TODO(phil): What does Round mean?
- Round: 1,
- CompLevel: match.CompLevel,
- R1: red[0],
- R2: red[1],
- R3: red[2],
- B1: blue[0],
- B2: blue[1],
- B3: blue[2],
+ Round: int32(match.SetNumber),
+ CompLevel: match.CompLevel,
+ R1: red[0],
+ R2: red[1],
+ R3: red[2],
+ B1: blue[0],
+ B2: blue[1],
+ B3: blue[2],
})
if err != nil {
respondWithError(w, http.StatusInternalServerError, fmt.Sprintf(
diff --git a/scouting/webserver/requests/requests_test.go b/scouting/webserver/requests/requests_test.go
index b864cf3..e2d9219 100644
--- a/scouting/webserver/requests/requests_test.go
+++ b/scouting/webserver/requests/requests_test.go
@@ -360,6 +360,7 @@
{
CompLevel: "qual",
MatchNumber: 1,
+ SetNumber: 2,
Alliances: scraping.Alliances{
Red: scraping.Alliance{
TeamKeys: []string{
@@ -411,7 +412,7 @@
expectedMatches := []db.Match{
{
MatchNumber: 1,
- Round: 1,
+ Round: 2,
CompLevel: "qual",
R1: 100,
R2: 200,