internal/analysis,worker: make Diagnostic.Source nullable
Make this new BigQuery column optional. Otherwise we can't
add it to an existing table.
Change-Id: Idf7932fd241f62a7e91093f68af318c4025ff9b6
Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/485855
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/internal/analysis/analysis.go b/internal/analysis/analysis.go
index 576e935..a0417d5 100644
--- a/internal/analysis/analysis.go
+++ b/internal/analysis/analysis.go
@@ -14,6 +14,7 @@
"strings"
"time"
+ bq "cloud.google.com/go/bigquery"
"golang.org/x/exp/maps"
"golang.org/x/pkgsite-metrics/internal/bigquery"
"golang.org/x/pkgsite-metrics/internal/derrors"
@@ -181,10 +182,10 @@
AnalyzerName string `bigquery:"analyzer_name"`
Error string `bigquery:"error"`
// These fields are from internal/worker.JSONDiagnostic.
- Category string `bigquery:"category"`
- Position string `bigquery:"position"`
- Message string `bigquery:"message"`
- Source string `bigquery:"source"`
+ Category string `bigquery:"category"`
+ Position string `bigquery:"position"`
+ Message string `bigquery:"message"`
+ Source bq.NullString `bigquery:"source"`
}
// SchemaVersion changes whenever the analysis schema changes.
diff --git a/internal/worker/analysis.go b/internal/worker/analysis.go
index 369ea4d..1bad789 100644
--- a/internal/worker/analysis.go
+++ b/internal/worker/analysis.go
@@ -20,6 +20,7 @@
"strconv"
"strings"
+ bq "cloud.google.com/go/bigquery"
"cloud.google.com/go/storage"
"golang.org/x/pkgsite-metrics/internal/analysis"
"golang.org/x/pkgsite-metrics/internal/derrors"
@@ -224,7 +225,7 @@
if err != nil {
return fmt.Errorf("reading %s:%d: %w", file, line, err)
}
- d.Source = source
+ d.Source = bq.NullString{StringVal: source, Valid: true}
}
return nil
}
diff --git a/internal/worker/analysis_test.go b/internal/worker/analysis_test.go
index fde7d16..45b3ced 100644
--- a/internal/worker/analysis_test.go
+++ b/internal/worker/analysis_test.go
@@ -12,6 +12,7 @@
"strings"
"testing"
+ bq "cloud.google.com/go/bigquery"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"golang.org/x/pkgsite-metrics/internal/analysis"
@@ -154,7 +155,10 @@
PackageID: "a.com/m",
AnalyzerName: "findcall",
Message: "call of G(...)",
- Source: "package p\nfunc F() { G() }\nfunc G() {}",
+ Source: bq.NullString{
+ StringVal: "package p\nfunc F() { G() }\nfunc G() {}",
+ Valid: true,
+ },
},
},
}