зеркало из https://github.com/golang/pkgsite.git
internal/postgres: use version_type from the versions table
To be consistent with other version information, use the version_type stored on the versions table. Updates b/130367504 Change-Id: I28940a30217f2abd1c688712ab89b5d4dce74d0e Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/453885 Reviewed-by: Julie Qiu <julieqiu@google.com>
This commit is contained in:
Родитель
374c7d89d7
Коммит
a0de32b395
|
@ -45,6 +45,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
|
|||
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
|
||||
ReadmeFilePath: "README.md",
|
||||
ReadmeContents: []byte("README FILE FOR TESTING."),
|
||||
VersionType: "release",
|
||||
},
|
||||
pkg: "my.mod/module/bar",
|
||||
pkgData: &internal.Package{
|
||||
|
@ -86,8 +87,8 @@ func TestFetchAndInsertVersion(t *testing.T) {
|
|||
// reflect.DeepEqual. Convert the DB time to UTC.
|
||||
got.CommitTime = got.CommitTime.UTC()
|
||||
|
||||
if diff := cmp.Diff(got, *test.versionData); diff != "" {
|
||||
t.Errorf("db.GetVersion(ctx, %q, %q) mismatch (-got +want):\n%s", test.modulePath, test.version, diff)
|
||||
if diff := cmp.Diff(*test.versionData, got); diff != "" {
|
||||
t.Errorf("db.GetVersion(ctx, %q, %q) mismatch (-want +got):\n%s", test.modulePath, test.version, diff)
|
||||
}
|
||||
|
||||
gotPkg, err := db.GetPackage(ctx, test.pkg, test.version)
|
||||
|
|
|
@ -194,9 +194,9 @@ func zipLicenseInfo(licenseTypes []string, licensePaths []string) ([]*internal.L
|
|||
// (module_path, version).
|
||||
func (db *DB) GetVersion(ctx context.Context, modulePath string, version string) (*internal.VersionInfo, error) {
|
||||
var (
|
||||
commitTime time.Time
|
||||
seriesPath, readmeFilePath string
|
||||
readmeContents []byte
|
||||
commitTime time.Time
|
||||
seriesPath, readmeFilePath, versionType string
|
||||
readmeContents []byte
|
||||
)
|
||||
|
||||
query := `
|
||||
|
@ -204,7 +204,8 @@ func (db *DB) GetVersion(ctx context.Context, modulePath string, version string)
|
|||
m.series_path,
|
||||
v.commit_time,
|
||||
v.readme_file_path,
|
||||
v.readme_contents
|
||||
v.readme_contents,
|
||||
v.version_type
|
||||
FROM
|
||||
versions v
|
||||
INNER JOIN
|
||||
|
@ -213,7 +214,7 @@ func (db *DB) GetVersion(ctx context.Context, modulePath string, version string)
|
|||
m.path = v.module_path
|
||||
WHERE module_path = $1 and version = $2;`
|
||||
row := db.QueryRowContext(ctx, query, modulePath, version)
|
||||
if err := row.Scan(&seriesPath, &commitTime, &readmeFilePath, &readmeContents); err != nil {
|
||||
if err := row.Scan(&seriesPath, &commitTime, &readmeFilePath, &readmeContents, &versionType); err != nil {
|
||||
return nil, fmt.Errorf("row.Scan(): %v", err)
|
||||
}
|
||||
return &internal.VersionInfo{
|
||||
|
@ -223,6 +224,7 @@ func (db *DB) GetVersion(ctx context.Context, modulePath string, version string)
|
|||
CommitTime: commitTime,
|
||||
ReadmeFilePath: readmeFilePath,
|
||||
ReadmeContents: readmeContents,
|
||||
VersionType: internal.VersionType(versionType),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -388,7 +390,7 @@ func getVersions(ctx context.Context, db *DB, path string, versionTypes []intern
|
|||
v.minor,
|
||||
v.patch,
|
||||
v.prerelease,
|
||||
p.version_type
|
||||
v.version_type
|
||||
FROM
|
||||
modules m
|
||||
INNER JOIN
|
||||
|
@ -579,7 +581,8 @@ func (db *DB) GetVersionForPackage(ctx context.Context, path, version string) (*
|
|||
p.license_paths,
|
||||
v.readme_file_path,
|
||||
v.readme_contents,
|
||||
v.commit_time
|
||||
v.commit_time,
|
||||
v.version_type
|
||||
FROM
|
||||
vw_licensed_packages p
|
||||
INNER JOIN
|
||||
|
@ -601,10 +604,11 @@ func (db *DB) GetVersionForPackage(ctx context.Context, path, version string) (*
|
|||
ORDER BY name, path;`
|
||||
|
||||
var (
|
||||
pkgPath, seriesPath, modulePath, pkgName, synopsis, suffix, readmeFilePath string
|
||||
readmeContents []byte
|
||||
commitTime time.Time
|
||||
licenseTypes, licensePaths []string
|
||||
pkgPath, seriesPath, modulePath, pkgName string
|
||||
synopsis, suffix, readmeFilePath, versionType string
|
||||
readmeContents []byte
|
||||
commitTime time.Time
|
||||
licenseTypes, licensePaths []string
|
||||
)
|
||||
|
||||
rows, err := db.QueryContext(ctx, query, version, path)
|
||||
|
@ -617,7 +621,8 @@ func (db *DB) GetVersionForPackage(ctx context.Context, path, version string) (*
|
|||
v.Version = version
|
||||
for rows.Next() {
|
||||
if err := rows.Scan(&pkgPath, &seriesPath, &modulePath, &pkgName, &synopsis, &suffix,
|
||||
pq.Array(&licenseTypes), pq.Array(&licensePaths), &readmeFilePath, &readmeContents, &commitTime); err != nil {
|
||||
pq.Array(&licenseTypes), pq.Array(&licensePaths), &readmeFilePath,
|
||||
&readmeContents, &commitTime, &versionType); err != nil {
|
||||
return nil, fmt.Errorf("row.Scan(): %v", err)
|
||||
}
|
||||
lics, err := zipLicenseInfo(licenseTypes, licensePaths)
|
||||
|
@ -629,6 +634,7 @@ func (db *DB) GetVersionForPackage(ctx context.Context, path, version string) (*
|
|||
v.ReadmeFilePath = readmeFilePath
|
||||
v.ReadmeContents = readmeContents
|
||||
v.CommitTime = commitTime
|
||||
v.VersionType = internal.VersionType(versionType)
|
||||
v.Packages = append(v.Packages, &internal.Package{
|
||||
Path: pkgPath,
|
||||
Name: pkgName,
|
||||
|
@ -839,8 +845,8 @@ func (db *DB) InsertVersion(ctx context.Context, version *internal.Version, lice
|
|||
}
|
||||
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO versions(module_path, version, commit_time, readme_file_path, readme_contents, major, minor, patch, prerelease)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9) ON CONFLICT DO NOTHING`,
|
||||
`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`,
|
||||
version.ModulePath,
|
||||
version.Version,
|
||||
version.CommitTime,
|
||||
|
@ -850,6 +856,7 @@ func (db *DB) InsertVersion(ctx context.Context, version *internal.Version, lice
|
|||
minorint,
|
||||
patchint,
|
||||
prerelease,
|
||||
version.VersionType,
|
||||
); err != nil {
|
||||
return fmt.Errorf("error inserting version: %v", err)
|
||||
}
|
||||
|
@ -876,7 +883,7 @@ func (db *DB) InsertVersion(ctx context.Context, version *internal.Version, lice
|
|||
var importValues []interface{}
|
||||
var pkgLicenseValues []interface{}
|
||||
for _, p := range version.Packages {
|
||||
pkgValues = append(pkgValues, p.Path, p.Synopsis, p.Name, version.Version, version.ModulePath, version.VersionType.String(), p.Suffix)
|
||||
pkgValues = append(pkgValues, p.Path, p.Synopsis, p.Name, version.Version, version.ModulePath, p.Suffix)
|
||||
|
||||
for _, l := range p.Licenses {
|
||||
pkgLicenseValues = append(pkgLicenseValues, version.ModulePath, version.Version, l.FilePath, p.Path)
|
||||
|
@ -893,7 +900,6 @@ func (db *DB) InsertVersion(ctx context.Context, version *internal.Version, lice
|
|||
"name",
|
||||
"version",
|
||||
"module_path",
|
||||
"version_type",
|
||||
"suffix",
|
||||
}
|
||||
table := "packages"
|
||||
|
|
|
@ -284,8 +284,7 @@ func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) {
|
|||
}
|
||||
|
||||
if tc.version != nil {
|
||||
if diff := cmp.Diff(&tc.version.VersionInfo, got, cmpopts.IgnoreFields(internal.VersionInfo{},
|
||||
"VersionType")); !tc.wantReadErr && diff != "" {
|
||||
if diff := cmp.Diff(&tc.version.VersionInfo, got); !tc.wantReadErr && diff != "" {
|
||||
t.Errorf("db.GetVersion(ctx, %q, %q) mismatch (-want +got):\n%s", tc.getModule, tc.getVersion, diff)
|
||||
}
|
||||
}
|
||||
|
@ -882,7 +881,7 @@ func TestPostgres_GetTaggedAndPseudoVersionsForPackageSeries(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, v := range got {
|
||||
if diff := cmp.Diff(wantPseudoVersions[i], v, cmpopts.IgnoreFields(internal.VersionInfo{}, "VersionType")); diff != "" {
|
||||
if diff := cmp.Diff(wantPseudoVersions[i], v); diff != "" {
|
||||
t.Errorf("db.GetPseudoVersionsForPackageSeries(%q) mismatch (-want +got):\n%s", tc.path, diff)
|
||||
}
|
||||
}
|
||||
|
@ -898,8 +897,7 @@ func TestPostgres_GetTaggedAndPseudoVersionsForPackageSeries(t *testing.T) {
|
|||
|
||||
for i, v := range got {
|
||||
|
||||
if diff := cmp.Diff(tc.wantTaggedVersions[i], v, cmpopts.IgnoreFields(internal.VersionInfo{},
|
||||
"VersionType")); diff != "" {
|
||||
if diff := cmp.Diff(tc.wantTaggedVersions[i], v); diff != "" {
|
||||
t.Errorf("db.GetTaggedVersionsForPackageSeries(%q) mismatch (-want +got):\n%s", tc.path, diff)
|
||||
}
|
||||
}
|
||||
|
@ -1014,8 +1012,7 @@ func TestGetVersionForPackage(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("db.GetVersionForPackage(ctx, %q, %q): %v", tc.path, tc.version, err)
|
||||
}
|
||||
if diff := cmp.Diff(tc.wantVersion, got,
|
||||
cmpopts.IgnoreFields(internal.Version{}, "VersionType")); diff != "" {
|
||||
if diff := cmp.Diff(tc.wantVersion, got); diff != "" {
|
||||
t.Errorf("db.GetVersionForPackage(ctx, %q, %q) mismatch (-want +got):\n%s", tc.path, tc.version, diff)
|
||||
}
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче