From a6b11d0236f98c3b6aedddfc76e2000768ab7e53 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Mon, 21 Aug 2023 14:04:07 +0200 Subject: [PATCH] Review comment --- cmd/internal/database/postgres/upgrade.go | 12 +++++------- go.mod | 1 + go.sum | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/internal/database/postgres/upgrade.go b/cmd/internal/database/postgres/upgrade.go index aa6365b..e99eb06 100644 --- a/cmd/internal/database/postgres/upgrade.go +++ b/cmd/internal/database/postgres/upgrade.go @@ -12,6 +12,8 @@ import ( "strings" "syscall" "time" + + "github.com/Masterminds/semver/v3" ) const ( @@ -195,15 +197,11 @@ func (db *Postgres) getBinaryVersion(pgConfigCmd string) (int, error) { if !found { return 0, fmt.Errorf("unable to detect postgres binary version in pg_config output, skipping upgrade, output:%q", binaryVersionString) } - binaryVersionMajorString, _, found := strings.Cut(binaryVersionString, ".") - if !found { - return 0, fmt.Errorf("unable to parse postgres binary version, skipping upgrade") - } - binaryVersionMajor, err := strconv.Atoi(binaryVersionMajorString) + v, err := semver.NewVersion(binaryVersionString) if err != nil { - return 0, fmt.Errorf("unable to parse postgres binary version to an int, skipping upgrade %w", err) + return 0, fmt.Errorf("unable to parse postgres binary version %w", err) } - return binaryVersionMajor, nil + return int(v.Major()), nil } func (db *Postgres) getDatabaseVersion(pgVersionFile string) (int, error) { diff --git a/go.mod b/go.mod index 2a6c70e..e20447d 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21 require ( cloud.google.com/go/storage v1.32.0 + github.com/Masterminds/semver/v3 v3.2.1 github.com/aws/aws-sdk-go v1.44.324 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/metal-stack/v v1.0.3 diff --git a/go.sum b/go.sum index 4de89f9..b179e57 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,8 @@ cloud.google.com/go/storage v1.32.0/go.mod h1:Hhh/dogNRGca7IWv1RC2YqEn0c0G77ctA/ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= +github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=