Skip to content

Commit 100ae60

Browse files
authored
fix: do not override collation on pg 15.8 (#3579)
1 parent 7cc76f1 commit 100ae60

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

internal/db/start/start.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/supabase/cli/internal/status"
2525
"github.com/supabase/cli/internal/utils"
2626
"github.com/supabase/cli/internal/utils/flags"
27+
"github.com/supabase/cli/pkg/config"
2728
"github.com/supabase/cli/pkg/migration"
2829
"github.com/supabase/cli/pkg/vault"
2930
)
@@ -75,7 +76,7 @@ func NewContainerConfig() container.Config {
7576
"S3_ACCESS_KEY="+utils.Config.Experimental.S3AccessKey,
7677
"S3_SECRET_KEY="+utils.Config.Experimental.S3SecretKey,
7778
)
78-
} else {
79+
} else if config.VersionCompare(utils.Config.Db.Image, "15.8.1.005") < 0 {
7980
env = append(env, "POSTGRES_INITDB_ARGS=--lc-collate=C.UTF-8")
8081
}
8182
config := container.Config{

pkg/config/config.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,8 @@ func (c *config) Load(path string, fsys fs.FS) error {
607607
if c.Db.MajorVersion > 14 {
608608
if version, err := fs.ReadFile(fsys, builder.PostgresVersionPath); err == nil {
609609
// 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))
610+
if VersionCompare(c.Db.Image, "15.1.0.55") >= 0 {
611+
c.Db.Image = replaceImageTag(Images.Pg, string(version))
613612
}
614613
}
615614
if version, err := fs.ReadFile(fsys, builder.RestVersionPath); err == nil && len(version) > 0 {
@@ -647,6 +646,22 @@ func (c *config) Load(path string, fsys fs.FS) error {
647646
return c.Validate(fsys)
648647
}
649648

649+
func VersionCompare(a, b string) int {
650+
var pA, pB string
651+
if vA := strings.Split(a, "."); len(vA) > 3 {
652+
a = strings.Join(vA[:3], ".")
653+
pA = strings.Join(vA[3:], ".")
654+
}
655+
if vB := strings.Split(b, "."); len(vB) > 3 {
656+
b = strings.Join(vB[:3], ".")
657+
pB = strings.Join(vB[3:], ".")
658+
}
659+
if r := semver.Compare("v"+a, "v"+b); r != 0 {
660+
return r
661+
}
662+
return semver.Compare("v"+pA, "v"+pB)
663+
}
664+
650665
func (c *baseConfig) resolve(builder pathBuilder, fsys fs.FS) error {
651666
// Update content paths
652667
for name, tmpl := range c.Auth.Email.Template {

pkg/config/config_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,28 @@ func TestLoadEnvIfExists(t *testing.T) {
615615
os.Unsetenv("ANOTHER_KEY")
616616
})
617617
}
618+
619+
func TestVersionCompare(t *testing.T) {
620+
var testcase = []struct {
621+
a string
622+
b string
623+
r int
624+
}{
625+
{"15.1.0.55", "15.1.0.55", 0},
626+
{"15.8.1.085", "15.1.0.55", 1},
627+
{"15.1.0.55", "15.8.1.085", -1},
628+
{"15.8.1", "15.8.1", 0},
629+
{"17", "15.8", 1},
630+
{"14", "15.8", -1},
631+
{"oriole-17", "oriole-17", 0},
632+
{"17", "oriole-17", 1},
633+
{"oriole-17", "17", -1},
634+
}
635+
636+
for _, tt := range testcase {
637+
t.Run(fmt.Sprintf("%s vs %s", tt.a, tt.b), func(t *testing.T) {
638+
result := VersionCompare(tt.a, tt.b)
639+
assert.Equal(t, tt.r, result)
640+
})
641+
}
642+
}

0 commit comments

Comments
 (0)