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>
38 files changed
tree: 196214b3a1f38288ec8ffa00bd808e2d4fb573b3
  1. cmd/
  2. content/
  3. internal/
  4. migrations/
  5. .gitignore
  6. all.bash
  7. CONTRIBUTING.md
  8. go.mod
  9. go.sum
  10. LICENSE
  11. PATENTS
  12. README.md
README.md

Go Module Discovery Site

Getting Started

Requirements

Migrations

Migrations are managed with the golang-migrate/migrate CLI tool.

To run all the migrations:

migrate -source file:migrations -database "postgres://localhost:5432/discovery-database?sslmode=disable" up

To create a new migration:

migrate create -ext sql -dir migrations -seq <title>

This creates two empty files in /migrations:

{version}_{title}.up.sql
{version}_{title}.down.sql

The two migration files are used to migrate “up” to the specified version from the previous version, and to migrate “down” to the previous version. See golang-migrate/migrate/MIGRATIONS.md for details.