aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres
diff options
context:
space:
mode:
authorChanning Kimble-Brown <channing@golang.org>2019-02-25 14:06:09 -0500
committerJulie Qiu <julie@golang.org>2020-03-27 16:46:33 -0400
commitdb97fa3db8fc8b45b509ec74f08142bb884fce8e (patch)
tree982b6721dce2ff2c79e13791c08b31d7933af4c0 /internal/postgres
parent10286b9fa61aa6ff6a00e88ed455d25a9473622d (diff)
downloadgo-x-pkgsite-db97fa3db8fc8b45b509ec74f08142bb884fce8e.tar.xz
internal, internal/postgres: merge license and readme structs into version
The ReadMe and License structs in internal/discovery.go are being merged into the Version struct to reflect the corresponding tables being merged into the versions table in the database. Change-Id: I78a2c05733bb935140c9c4c86237e673921f5b36 Reviewed-on: https://team-review.git.corp.google.com/c/422452 Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/postgres')
-rw-r--r--internal/postgres/postgres.go25
-rw-r--r--internal/postgres/postgres_test.go19
2 files changed, 22 insertions, 22 deletions
diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go
index 14f55de9..50b49b9e 100644
--- a/internal/postgres/postgres.go
+++ b/internal/postgres/postgres.go
@@ -91,9 +91,8 @@ func (db *DB) InsertVersionLogs(logs []*internal.VersionLog) error {
// GetVersion fetches a Version from the database with the primary key
// (name, version).
func (db *DB) GetVersion(name string, version string) (*internal.Version, error) {
- var synopsis string
var commitTime, createdAt, updatedAt time.Time
- var license string
+ var synopsis, licenseName, readme string
query := `
SELECT
@@ -101,12 +100,13 @@ func (db *DB) GetVersion(name string, version string) (*internal.Version, error)
updated_at,
synopsis,
commit_time,
- license
+ license_name,
+ readme
FROM versions
WHERE name = $1 and version = $2;`
row := db.QueryRow(query, name, version)
- if err := row.Scan(&createdAt, &updatedAt, &synopsis, &commitTime, &license); err != nil {
+ if err := row.Scan(&createdAt, &updatedAt, &synopsis, &commitTime, &licenseName, &readme); err != nil {
return nil, err
}
return &internal.Version{
@@ -115,12 +115,11 @@ func (db *DB) GetVersion(name string, version string) (*internal.Version, error)
Module: &internal.Module{
Name: name,
},
- Version: version,
- Synopsis: synopsis,
- CommitTime: commitTime,
- License: &internal.License{
- Type: license,
- },
+ Version: version,
+ Synopsis: synopsis,
+ CommitTime: commitTime,
+ LicenseName: licenseName,
+ ReadMe: readme,
}, nil
}
@@ -157,14 +156,14 @@ func (db *DB) InsertVersion(version *internal.Version) error {
// licenses, dependencies, and packages (the rest of the fields in the
// internal.Version struct)
if _, err := tx.Exec(
- `INSERT INTO versions(name, version, synopsis, commit_time, license, deleted)
+ `INSERT INTO versions(name, version, synopsis, commit_time, license_name, readme)
VALUES($1,$2,$3,$4,$5,$6)`,
version.Module.Name,
version.Version,
version.Synopsis,
version.CommitTime,
- version.License.Type,
- false,
+ version.LicenseName,
+ version.ReadMe,
); err != nil {
return err
}
diff --git a/internal/postgres/postgres_test.go b/internal/postgres/postgres_test.go
index 11d0d24b..67b3c0b8 100644
--- a/internal/postgres/postgres_test.go
+++ b/internal/postgres/postgres_test.go
@@ -52,15 +52,16 @@ func TestPostgres_ReadAndWriteVersion(t *testing.T) {
}
var testVersion = &internal.Version{
- Module: module,
- Version: "v1.0.0",
- Synopsis: "This is a synopsis",
- License: &internal.License{},
- ReadMe: &internal.ReadMe{},
- CommitTime: time.Now(),
- Packages: []*internal.Package{},
- Dependencies: []*internal.Version{},
- Dependents: []*internal.Version{},
+ Module: module,
+ Version: "v1.0.0",
+ Synopsis: "This is a synopsis",
+ LicenseName: "licensename",
+ LicenseContents: "licensecontents",
+ ReadMe: "readme",
+ CommitTime: time.Now(),
+ Packages: []*internal.Package{},
+ Dependencies: []*internal.Version{},
+ Dependents: []*internal.Version{},
}
testCases := []struct {