Skip to content

Commit a0e32f2

Browse files
ethanndicksonstirby
authored andcommitted
fix: pin pg_dump version when generating schema (#19696)
The latest release of all `pg_dump` major versions, going back to 13, started inserting `\restrict` `\unrestrict` keywords into dumps. This currently breaks sqlc in `gen/dump` and our check migration script. Full details of the postgres change are available here: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=575f54d4c To fix, we'll always use the `pg_dump` in our postgres 13.21 docker image for schema dumps, instead of what's on the runner/local machine. Coder doesn't restore from postgres dumps, so we're not vulnerable to attacks that would be patched by the latest postgres version. Regardless, we'll unpin ASAP. Once sqlc is updated to handle these keywords, we need to start stripping them when comparing the schema in the migration check script, and then we can unpin the pg_dump version. This is being tracked at coder/internal#965 (cherry picked from commit 1b4ce09)
1 parent d7c4833 commit a0e32f2

File tree

1 file changed

+21
-17
lines changed
  • coderd/database/dbtestutil

1 file changed

+21
-17
lines changed

coderd/database/dbtestutil/db.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os/exec"
1111
"path/filepath"
1212
"regexp"
13-
"strconv"
1413
"strings"
1514
"testing"
1615
"time"
@@ -254,26 +253,31 @@ func PGDump(dbURL string) ([]byte, error) {
254253
return stdout.Bytes(), nil
255254
}
256255

257-
const minimumPostgreSQLVersion = 13
256+
const (
257+
minimumPostgreSQLVersion = 13
258+
postgresImageSha = "sha256:467e7f2fb97b2f29d616e0be1d02218a7bbdfb94eb3cda7461fd80165edfd1f7"
259+
)
258260

259261
// PGDumpSchemaOnly is for use by gen/dump only.
260262
// It runs pg_dump against dbURL and sets a consistent timezone and encoding.
261263
func PGDumpSchemaOnly(dbURL string) ([]byte, error) {
262264
hasPGDump := false
263-
if _, err := exec.LookPath("pg_dump"); err == nil {
264-
out, err := exec.Command("pg_dump", "--version").Output()
265-
if err == nil {
266-
// Parse output:
267-
// pg_dump (PostgreSQL) 14.5 (Ubuntu 14.5-0ubuntu0.22.04.1)
268-
parts := strings.Split(string(out), " ")
269-
if len(parts) > 2 {
270-
version, err := strconv.Atoi(strings.Split(parts[2], ".")[0])
271-
if err == nil && version >= minimumPostgreSQLVersion {
272-
hasPGDump = true
273-
}
274-
}
275-
}
276-
}
265+
// TODO: Temporarily pin pg_dump to the docker image until
266+
// https://github.com/sqlc-dev/sqlc/issues/4065 is resolved.
267+
// if _, err := exec.LookPath("pg_dump"); err == nil {
268+
// out, err := exec.Command("pg_dump", "--version").Output()
269+
// if err == nil {
270+
// // Parse output:
271+
// // pg_dump (PostgreSQL) 14.5 (Ubuntu 14.5-0ubuntu0.22.04.1)
272+
// parts := strings.Split(string(out), " ")
273+
// if len(parts) > 2 {
274+
// version, err := strconv.Atoi(strings.Split(parts[2], ".")[0])
275+
// if err == nil && version >= minimumPostgreSQLVersion {
276+
// hasPGDump = true
277+
// }
278+
// }
279+
// }
280+
// }
277281

278282
cmdArgs := []string{
279283
"pg_dump",
@@ -298,7 +302,7 @@ func PGDumpSchemaOnly(dbURL string) ([]byte, error) {
298302
"run",
299303
"--rm",
300304
"--network=host",
301-
fmt.Sprintf("%s:%d", postgresImage, minimumPostgreSQLVersion),
305+
fmt.Sprintf("%s:%d@%s", postgresImage, minimumPostgreSQLVersion, postgresImageSha),
302306
}, cmdArgs...)
303307
}
304308
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) //#nosec

0 commit comments

Comments
 (0)