aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module.go
diff options
context:
space:
mode:
authorMiguel Acero <acero@google.com>2020-08-10 15:08:37 -0400
committerMiguel Acero <acero@google.com>2020-08-13 20:20:06 +0000
commit67f483bf812dbb53ae472097c9f729cd5ebbdd2c (patch)
tree9485ca705f5f6eaf0c643ca7f22b774acadfaf7c /internal/postgres/insert_module.go
parenta1b9579989302b4f1ba71cd3bbb0ca0364ab09d4 (diff)
downloadgo-x-pkgsite-67f483bf812dbb53ae472097c9f729cd5ebbdd2c.tar.xz
internal/postgres: populate modules.incompatible field
This change modifies the InsertModule function to insert modules with an Incompatible field for the new Incompatible column in the modules table. A test is added to check the latest version of inserted modules. Updates golang/go#37714 Change-Id: I7ef04b8709f9499d747d9795531cbc83b5de25ad Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/247757 Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/insert_module.go')
-rw-r--r--internal/postgres/insert_module.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index e33f57ca..512c803b 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -183,8 +183,9 @@ func insertModule(ctx context.Context, db *database.DB, m *internal.Module) (_ i
series_path,
source_info,
redistributable,
- has_go_mod)
- VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10, $11)
+ has_go_mod,
+ incompatible)
+ VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)
ON CONFLICT
(module_path, version)
DO UPDATE SET
@@ -204,6 +205,7 @@ func insertModule(ctx context.Context, db *database.DB, m *internal.Module) (_ i
sourceInfoJSON,
m.IsRedistributable,
m.HasGoMod,
+ isIncompatible(m.Version),
).Scan(&moduleID)
if err != nil {
return 0, err
@@ -557,13 +559,19 @@ func lock(ctx context.Context, tx *database.DB, modulePath string) (err error) {
return nil
}
+// isIncompatible reports whether the build metadata of the version is
+// "+incompatible", https://semver.org clause 10.
+func isIncompatible(version string) bool {
+ return strings.HasSuffix(version, "+incompatible")
+}
+
// isLatestVersion reports whether version is the latest version of the module.
func isLatestVersion(ctx context.Context, db *database.DB, modulePath, version string) (_ bool, err error) {
defer derrors.Wrap(&err, "isLatestVersion(ctx, tx, %q)", modulePath)
row := db.QueryRow(ctx, `
SELECT version FROM modules WHERE module_path = $1
- ORDER BY version_type = 'release' DESC, sort_version DESC
+ ORDER BY incompatible, version_type = 'release' DESC, sort_version DESC
LIMIT 1`,
modulePath)
var v string