From 67f483bf812dbb53ae472097c9f729cd5ebbdd2c Mon Sep 17 00:00:00 2001 From: Miguel Acero Date: Mon, 10 Aug 2020 15:08:37 -0400 Subject: 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 --- internal/postgres/insert_module.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'internal/postgres/insert_module.go') 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 -- cgit v1.3