diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-01-08 09:09:32 -0500 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-03-27 16:46:50 -0400 |
| commit | 7ec22257d2b75c6250aeff03cd19f897a21c97e4 (patch) | |
| tree | a39c4be0bacb1504adbe5b8f5c78ace6fd5346eb /internal/postgres/versionstate.go | |
| parent | 9a2ee3d7c05c0cb09536522ed776ff67f92f3aac (diff) | |
| download | go-x-pkgsite-7ec22257d2b75c6250aeff03cd19f897a21c97e4.tar.xz | |
internal/postgres: read and write module_version_states.go_mod_path
This CL adds go_mod_path to the low-level code that reads and writes
the module_version_states table.
A later CL will plumb the path from fetch through to the insert call.
Change-Id: I5822d4faae0b1e2aec22ea9071ad6f0908c25a6e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/632523
Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/postgres/versionstate.go')
| -rw-r--r-- | internal/postgres/versionstate.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/internal/postgres/versionstate.go b/internal/postgres/versionstate.go index ddb70d5b..2d79298c 100644 --- a/internal/postgres/versionstate.go +++ b/internal/postgres/versionstate.go @@ -42,19 +42,20 @@ func (db *DB) InsertIndexVersions(ctx context.Context, versions []*internal.Inde // UpsertVersionState inserts or updates the module_version_state table with // the results of a fetch operation for a given module version. -func (db *DB) UpsertVersionState(ctx context.Context, modulePath, vers, appVersion string, timestamp time.Time, status int, fetchErr error) (err error) { - derrors.Wrap(&err, "UpsertVersionState(ctx, %q, %q, %q, %s, %d, %v", - modulePath, vers, appVersion, timestamp, status, fetchErr) +func (db *DB) UpsertVersionState(ctx context.Context, modulePath, vers, appVersion string, timestamp time.Time, status int, goModPath string, fetchErr error) (err error) { + derrors.Wrap(&err, "UpsertVersionState(ctx, %q, %q, %q, %s, %d, %q, %v", + modulePath, vers, appVersion, timestamp, status, goModPath, fetchErr) ctx, span := trace.StartSpan(ctx, "UpsertVersionState") defer span.End() query := ` - INSERT INTO module_version_states AS mvs (module_path, version, sort_version, app_version, index_timestamp, status, error) - VALUES ($1, $2, $3, $4, $5, $6, $7) + INSERT INTO module_version_states AS mvs (module_path, version, sort_version, app_version, index_timestamp, status, go_mod_path, error) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (module_path, version) DO UPDATE SET app_version=excluded.app_version, status=excluded.status, + go_mod_path=excluded.go_mod_path, error=excluded.error, try_count=mvs.try_count+1, last_processed_at=CURRENT_TIMESTAMP, @@ -73,7 +74,7 @@ func (db *DB) UpsertVersionState(ctx context.Context, modulePath, vers, appVersi sqlErrorMsg = sql.NullString{Valid: true, String: fetchErr.Error()} } result, err := db.db.Exec(ctx, query, - modulePath, vers, version.ForSorting(vers), appVersion, timestamp, status, sqlErrorMsg) + modulePath, vers, version.ForSorting(vers), appVersion, timestamp, status, goModPath, sqlErrorMsg) if err != nil { return err } @@ -142,7 +143,8 @@ const versionStateColumns = ` try_count, last_processed_at, next_processed_after, - app_version` + app_version, + go_mod_path` // scanVersionState constructs an *internal.VersionState from the given // scanner. It expects columns to be in the order of versionStateColumns. @@ -152,11 +154,11 @@ func scanVersionState(scan func(dest ...interface{}) error) (*internal.VersionSt indexTimestamp, createdAt, nextProcessedAfter time.Time lastProcessedAt pq.NullTime status sql.NullInt64 - errorMsg sql.NullString + errorMsg, goModPath sql.NullString tryCount int ) if err := scan(&modulePath, &version, &indexTimestamp, &createdAt, &status, &errorMsg, - &tryCount, &lastProcessedAt, &nextProcessedAfter, &appVersion); err != nil { + &tryCount, &lastProcessedAt, &nextProcessedAfter, &appVersion, &goModPath); err != nil { return nil, err } v := &internal.VersionState{ @@ -176,6 +178,10 @@ func scanVersionState(scan func(dest ...interface{}) error) (*internal.VersionSt s := errorMsg.String v.Error = &s } + if goModPath.Valid { + s := goModPath.String + v.GoModPath = &s + } if lastProcessedAt.Valid { lp := lastProcessedAt.Time v.LastProcessedAt = &lp |
