Skip to content

Commit 3c40698

Browse files
authored
chore: Enforce PostgreSQL >=13 (#4612)
* chore: Enforce PostgreSQL >=13 Fixes #4608. * Fix version string parsing
1 parent 614e40c commit 3c40698

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cli/server.go

+18
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,23 @@ 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+
versionStr = strings.Split(versionStr, " ")[0]
407+
if semver.Compare("v"+versionStr, "v13") < 0 {
408+
return xerrors.New("PostgreSQL version must be v13.0.0 or higher!")
409+
}
392410

393411
err = sqlDB.Ping()
394412
if err != nil {

cli/server_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func TestServer(t *testing.T) {
6060
"--postgres-url", connectionURL,
6161
"--cache-dir", t.TempDir(),
6262
)
63+
pty := ptytest.New(t)
64+
root.SetOutput(pty.Output())
65+
root.SetErr(pty.Output())
6366
errC := make(chan error, 1)
6467
go func() {
6568
errC <- root.ExecuteContext(ctx)

0 commit comments

Comments
 (0)