Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 544338d

Browse files
committed
chore: Enforce PostgreSQL >=13
Fixes #4608.
1 parent 614e40c commit 544338d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cli/server.go

+17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/spf13/afero"
3434
"github.com/spf13/cobra"
3535
"go.opentelemetry.io/otel/trace"
36+
"golang.org/x/mod/semver"
3637
"golang.org/x/oauth2"
3738
xgithub "golang.org/x/oauth2/github"
3839
"golang.org/x/sync/errgroup"
@@ -389,6 +390,22 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
389390
return xerrors.Errorf("dial postgres: %w", err)
390391
}
391392
defer sqlDB.Close()
393+
// Ensure the PostgreSQL version is >=13.0.0!
394+
version, err := sqlDB.QueryContext(ctx, "SHOW server_version;")
395+
if err != nil {
396+
return xerrors.Errorf("get postgres version: %w", err)
397+
}
398+
if !version.Next() {
399+
return xerrors.Errorf("no rows returned for version select")
400+
}
401+
var versionStr string
402+
err = version.Scan(&versionStr)
403+
if err != nil {
404+
return xerrors.Errorf("scan version: %w", err)
405+
}
406+
if semver.Compare("v"+versionStr, "v13") < 0 {
407+
return xerrors.New("PostgreSQL version must be v13.0.0 or higher!")
408+
}
392409

393410
err = sqlDB.Ping()
394411
if err != nil {

0 commit comments

Comments
 (0)