internal/postgres: only store license name on Version

The Version struct is updated to reflect that change from the migration in
092e728bbbfdd15a40165f52110a6aec4bf55548:

- Version.LicenseName is renamed to License
- Version.LicenseContents is removed

SQL queries for postgres.GetVersion and postgres.InsertVersion are
also fixed to reflect the migration changes.

Change-Id: I3a9c7cc9e02ca839741acac7a8370c4c6237fe7e
Reviewed-on: https://team-review.git.corp.google.com/c/423370
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
This commit is contained in:
Julie Qiu 2019-02-26 15:49:25 -05:00
Родитель 51a2196a46
Коммит 518ce0a7d6
3 изменённых файлов: 34 добавлений и 32 удалений

Просмотреть файл

@ -26,18 +26,17 @@ type Module struct {
// A Version is a specific, reproducible build of a module.
type Version struct {
Module *Module
Version string
CreatedAt time.Time
UpdatedAt time.Time
Synopsis string
CommitTime time.Time
LicenseName string
LicenseContents string
ReadMe string
Packages []*Package
Dependencies []*Version
Dependents []*Version
Module *Module
Version string
CreatedAt time.Time
UpdatedAt time.Time
Synopsis string
CommitTime time.Time
License string
ReadMe string
Packages []*Package
Dependencies []*Version
Dependents []*Version
}
// A Package is a group of one or more Go source files with the same package

Просмотреть файл

@ -92,7 +92,7 @@ func (db *DB) InsertVersionLogs(logs []*internal.VersionLog) error {
// (name, version).
func (db *DB) GetVersion(name string, version string) (*internal.Version, error) {
var commitTime, createdAt, updatedAt time.Time
var synopsis, licenseName, readme string
var synopsis, license, readme string
query := `
SELECT
@ -100,13 +100,13 @@ func (db *DB) GetVersion(name string, version string) (*internal.Version, error)
updated_at,
synopsis,
commit_time,
license_name,
license,
readme
FROM versions
WHERE name = $1 and version = $2;`
row := db.QueryRow(query, name, version)
if err := row.Scan(&createdAt, &updatedAt, &synopsis, &commitTime, &licenseName, &readme); err != nil {
if err := row.Scan(&createdAt, &updatedAt, &synopsis, &commitTime, &license, &readme); err != nil {
return nil, err
}
return &internal.Version{
@ -115,11 +115,11 @@ func (db *DB) GetVersion(name string, version string) (*internal.Version, error)
Module: &internal.Module{
Name: name,
},
Version: version,
Synopsis: synopsis,
CommitTime: commitTime,
LicenseName: licenseName,
ReadMe: readme,
Version: version,
Synopsis: synopsis,
CommitTime: commitTime,
License: license,
ReadMe: readme,
}, nil
}
@ -156,13 +156,13 @@ 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_name, readme)
`INSERT INTO versions(name, version, synopsis, commit_time, license, readme)
VALUES($1,$2,$3,$4,$5,$6)`,
version.Module.Name,
version.Version,
version.Synopsis,
version.CommitTime,
version.LicenseName,
version.License,
version.ReadMe,
); err != nil {
return err

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package postgres
import (
@ -52,16 +56,15 @@ func TestPostgres_ReadAndWriteVersion(t *testing.T) {
}
var testVersion = &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{},
Module: module,
Version: "v1.0.0",
Synopsis: "This is a synopsis",
License: "licensename",
ReadMe: "readme",
CommitTime: time.Now(),
Packages: []*internal.Package{},
Dependencies: []*internal.Version{},
Dependents: []*internal.Version{},
}
testCases := []struct {