diff options
| author | Rob Findley <rfindley@google.com> | 2019-05-14 16:24:39 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-03-27 16:46:37 -0400 |
| commit | 2dd4be5f74beb684932fa9bcb6e612f9b9b99b5d (patch) | |
| tree | 196214b3a1f38288ec8ffa00bd808e2d4fb573b3 /internal/postgres/postgres.go | |
| parent | 84d44616b222ca191afb5af3d286a4db8e6ddbd6 (diff) | |
| download | go-x-pkgsite-2dd4be5f74beb684932fa9bcb6e612f9b9b99b5d.tar.xz | |
internal/proxy,internal/postgres: overwrite versions on fetch
This CL modifies postgres.InsertVersion overwrite version data, rather
than defaulting to ON CONFLICT DO NOTHING. This is achieved by first
deleting any existing version within the transaction, which will cascade
to all version data.
Testing this was a bit difficult due to the way the fake proxy is
implemented. In order to make this easier and facilitate easier testing
down the road, the fake proxy was modified to dynamically generate its
endpoints based on version information, allowing for the serving of
purely in-memory versions.
Since some common patterns are emerging in our tests, add an
internal/testhelper package.
Fixes b/132710180
Change-Id: I91137335d58c133d9de06ffe88e66b1f7846aa44
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/466417
Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/postgres/postgres.go')
| -rw-r--r-- | internal/postgres/postgres.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go index 06134596..dc392ce0 100644 --- a/internal/postgres/postgres.go +++ b/internal/postgres/postgres.go @@ -958,6 +958,15 @@ func (db *DB) InsertVersion(ctx context.Context, version *internal.Version, lice return fmt.Errorf("padPrerelease(%q): %v", version.Version, err) } + // If the version exists, delete it to force an overwrite. This allows us + // to selectively repopulate data after a code change. + if _, err := tx.ExecContext(ctx, + `DELETE FROM versions WHERE module_path=$1 AND version=$2`, + version.ModulePath, + version.Version, + ); err != nil { + return fmt.Errorf("error deleting existing versions: %v", err) + } if _, err := tx.ExecContext(ctx, `INSERT INTO versions(module_path, version, commit_time, readme_file_path, readme_contents, major, minor, patch, prerelease, version_type) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) ON CONFLICT DO NOTHING`, |
