From 518ce0a7d6f1eecb74b12aa02e924e8f71f0697b Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Tue, 26 Feb 2019 15:49:25 -0500 Subject: [PATCH] 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 --- internal/discovery.go | 23 +++++++++++------------ internal/postgres/postgres.go | 20 ++++++++++---------- internal/postgres/postgres_test.go | 23 +++++++++++++---------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/internal/discovery.go b/internal/discovery.go index 049d4d48..3bf19e3c 100644 --- a/internal/discovery.go +++ b/internal/discovery.go @@ -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 diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go index 50b49b9e..32d6d518 100644 --- a/internal/postgres/postgres.go +++ b/internal/postgres/postgres.go @@ -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 diff --git a/internal/postgres/postgres_test.go b/internal/postgres/postgres_test.go index 67b3c0b8..f3f593d9 100644 --- a/internal/postgres/postgres_test.go +++ b/internal/postgres/postgres_test.go @@ -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 {