Skip to content

Commit 2d3bd36

Browse files
feat(cli): setup postgres17 for local development (#3387)
* feat(cli): setup postgres17 for local development * chore: use v17 by default * chore: nitpick * chore: apply pr comments * chore: fix lint * chore: set default image based on major version * chore: use current db image for dump --------- Co-authored-by: Qiao Han <[email protected]>
1 parent 2b5458a commit 2d3bd36

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

internal/db/dump/dump.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/jackc/pgconn"
1515
"github.com/spf13/afero"
1616
"github.com/supabase/cli/internal/utils"
17-
cliConfig "github.com/supabase/cli/pkg/config"
1817
)
1918

2019
var (
@@ -173,7 +172,7 @@ func dump(ctx context.Context, config pgconn.Config, script string, env []string
173172
return utils.DockerRunOnceWithConfig(
174173
ctx,
175174
container.Config{
176-
Image: cliConfig.Images.Pg15,
175+
Image: utils.Config.Db.Image,
177176
Env: allEnvs,
178177
Cmd: []string{"bash", "-c", script, "--"},
179178
},

pkg/config/config.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func NewConfig(editors ...ConfigEditor) config {
333333
KongImage: Images.Kong,
334334
},
335335
Db: db{
336-
Image: Images.Pg15,
336+
Image: Images.Pg,
337337
Password: "postgres",
338338
RootKey: Secret{
339339
Value: "d4dc5b6d4a1d6a10b2c1e76112c994d65db7cec380572cc1839624d4be3fa275",
@@ -596,12 +596,22 @@ func (c *config) Load(path string, fsys fs.FS) error {
596596
c.Api.ExternalUrl = apiUrl.String()
597597
}
598598
// Update image versions
599-
if version, err := fs.ReadFile(fsys, builder.PostgresVersionPath); err == nil {
600-
if strings.HasPrefix(string(version), "15.") && semver.Compare(string(version[3:]), "1.0.55") >= 0 {
601-
c.Db.Image = replaceImageTag(Images.Pg15, string(version))
602-
}
599+
switch c.Db.MajorVersion {
600+
case 13:
601+
c.Db.Image = pg15
602+
case 14:
603+
c.Db.Image = pg14
604+
case 15:
605+
c.Db.Image = pg15
603606
}
604607
if c.Db.MajorVersion > 14 {
608+
if version, err := fs.ReadFile(fsys, builder.PostgresVersionPath); err == nil {
609+
// Only replace image if postgres version is above 15.1.0.55
610+
if strings.HasPrefix(string(version), fmt.Sprintf("%d.", c.Db.MajorVersion)) &&
611+
(c.Db.MajorVersion != 15 || semver.Compare(string(version[3:]), "1.0.55") >= 0) {
612+
c.Db.Image = replaceImageTag(pg15, string(version))
613+
}
614+
}
605615
if version, err := fs.ReadFile(fsys, builder.RestVersionPath); err == nil && len(version) > 0 {
606616
c.Api.Image = replaceImageTag(Images.Postgrest, string(version))
607617
}
@@ -725,10 +735,8 @@ func (c *config) Validate(fsys fs.FS) error {
725735
return errors.New("Missing required field in config: db.major_version")
726736
case 12:
727737
return errors.New("Postgres version 12.x is unsupported. To use the CLI, either start a new project or follow project migration steps here: https://supabase.com/docs/guides/database#migrating-between-projects.")
728-
case 13:
729-
c.Db.Image = pg13
730-
case 14:
731-
c.Db.Image = pg14
738+
case 13, 14, 17:
739+
// TODO: support oriole db 17 eventually
732740
case 15:
733741
if len(c.Experimental.OrioleDBVersion) > 0 {
734742
c.Db.Image = "supabase/postgres:orioledb-" + c.Experimental.OrioleDBVersion

pkg/config/constants.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
const (
1212
pg13 = "supabase/postgres:13.3.0"
1313
pg14 = "supabase/postgres:14.1.0.89"
14+
pg15 = "supabase/postgres:15.8.1.069"
1415
deno2 = "supabase/edge-runtime:v1.68.0-develop.13"
1516
)
1617

1718
type images struct {
18-
Pg15 string `mapstructure:"pg15"`
19+
Pg string `mapstructure:"pg"`
1920
// Append to Services when adding new dependencies below
2021
Kong string `mapstructure:"kong"`
2122
Inbucket string `mapstructure:"mailpit"`

pkg/config/templates/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Exposed for updates by .github/dependabot.yml
2-
FROM supabase/postgres:15.8.1.060 AS pg15
2+
FROM supabase/postgres:17.4.1.012 AS pg
33
# Append to ServiceImages when adding new dependencies below
44
FROM library/kong:2.8.1 AS kong
55
FROM axllent/mailpit:v1.22.3 AS mailpit

tools/selfhost/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func updateSelfHosted(ctx context.Context, branch string) error {
6161
}
6262

6363
func getStableVersions() map[string]string {
64-
images := append(config.Images.Services(), config.Images.Pg15)
64+
images := append(config.Images.Services(), config.Images.Pg)
6565
result := make(map[string]string, len(images))
6666
for _, img := range images {
6767
parts := strings.Split(img, ":")

0 commit comments

Comments
 (0)