• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 11267309158

10 Oct 2024 04:12AM UTC coverage: 60.211% (-0.04%) from 60.248%
11267309158

Pull #2754

github

sweatybridge
feat: support postgres config update without restart
Pull Request #2754: feat: support postgres config update without restart

4 of 9 new or added lines in 2 files covered. (44.44%)

5 existing lines in 1 file now uncovered.

6516 of 10822 relevant lines covered (60.21%)

6.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/postgresConfig/update/update.go
1
package update
2

3
import (
4
        "bytes"
5
        "context"
6
        "encoding/json"
7
        "strconv"
8
        "strings"
9

10
        "github.com/go-errors/errors"
11
        "github.com/spf13/afero"
12
        "github.com/supabase/cli/internal/postgresConfig/get"
13
        "github.com/supabase/cli/internal/utils"
14
)
15

NEW
16
func Run(ctx context.Context, projectRef string, values []string, replaceOverrides, noRestart bool, fsys afero.Fs) error {
×
17
        // 1. Prepare config overrides
×
18
        newConfigOverrides := make(map[string]string)
×
19
        for _, config := range values {
×
20
                splits := strings.Split(config, "=")
×
21
                if len(splits) != 2 {
×
22
                        return errors.Errorf("expected config value in key:value format, received: '%s'", config)
×
23
                }
×
24
                newConfigOverrides[splits[0]] = splits[1]
×
25
        }
26
        // 2. If not in replace mode, retrieve current overrides
27
        finalOverrides := make(map[string]interface{})
×
28
        {
×
29
                if !replaceOverrides {
×
30
                        config, err := get.GetCurrentPostgresConfig(ctx, projectRef)
×
31
                        if err != nil {
×
32
                                return err
×
33
                        }
×
34
                        finalOverrides = config
×
35
                }
36
        }
37
        // 3. Create the list of final overrides
38
        {
×
39
                for k, v := range newConfigOverrides {
×
40
                        // this is hacky - if we're able to convert the value to an integer, we do so
×
41
                        // if we start supporting config fields with e.g. floating pt overrides this'll need to be updated
×
42
                        attemptedConvert, err := strconv.Atoi(v)
×
43
                        if err != nil {
×
44
                                finalOverrides[k] = v
×
45
                        } else {
×
46
                                finalOverrides[k] = attemptedConvert
×
47
                        }
×
48
                }
49
        }
50
        // 4. update config overrides and print out final result
51
        {
×
NEW
52
                if noRestart {
×
NEW
53
                        finalOverrides["restart_database"] = false
×
NEW
54
                }
×
55
                bts, err := json.Marshal(finalOverrides)
×
56
                if err != nil {
×
57
                        return errors.Errorf("failed to serialize config overrides: %w", err)
×
58
                }
×
59
                resp, err := utils.GetSupabase().V1UpdatePostgresConfigWithBodyWithResponse(ctx, projectRef, "application/json", bytes.NewReader(bts))
×
60
                if err != nil {
×
61
                        return errors.Errorf("failed to update config overrides: %w", err)
×
62
                }
×
63
                if resp.JSON200 == nil {
×
64
                        if resp.StatusCode() == 400 {
×
65
                                return errors.Errorf("failed to update config overrides: %s (%s). This usually indicates that an unsupported or invalid config override was attempted. Please refer to https://supabase.com/docs/guides/platform/custom-postgres-config", resp.Status(), string(resp.Body))
×
66
                        }
×
67
                        return errors.Errorf("failed to update config overrides: %s (%s)", resp.Status(), string(resp.Body))
×
68
                }
69
        }
70
        return get.Run(ctx, projectRef, fsys)
×
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc