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

supabase / cli / 19288913427

12 Nov 2025 06:47AM UTC coverage: 54.407% (-0.3%) from 54.689%
19288913427

Pull #4429

github

web-flow
Merge 1cc083715 into 408904212
Pull Request #4429: fix: mark database linking error as non-fatal

33 of 92 new or added lines in 6 files covered. (35.87%)

29 existing lines in 6 files now uncovered.

6358 of 11686 relevant lines covered (54.41%)

6.1 hits per line

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

0.0
/internal/branches/get/get.go
1
package get
2

3
import (
4
        "context"
5
        "fmt"
6
        "os"
7

8
        "github.com/go-errors/errors"
9
        "github.com/google/uuid"
10
        "github.com/jackc/pgconn"
11
        "github.com/spf13/afero"
12
        "github.com/supabase/cli/internal/projects/apiKeys"
13
        "github.com/supabase/cli/internal/utils"
14
        "github.com/supabase/cli/internal/utils/flags"
15
        "github.com/supabase/cli/pkg/api"
16
        "github.com/supabase/cli/pkg/cast"
17
)
18

19
func Run(ctx context.Context, branchId string, fsys afero.Fs) error {
×
20
        detail, err := getBranchDetail(ctx, branchId)
×
21
        if err != nil {
×
22
                return err
×
23
        }
×
24

25
        if utils.OutputFormat.Value != utils.OutputPretty {
×
26
                keys, err := apiKeys.RunGetApiKeys(ctx, detail.Ref)
×
27
                if err != nil {
×
28
                        return err
×
29
                }
×
NEW
30
                pooler, err := utils.GetPoolerConfigPrimary(ctx, detail.Ref)
×
31
                if err != nil {
×
32
                        return err
×
33
                }
×
34
                envs := toStandardEnvs(detail, pooler, keys)
×
35
                return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, envs)
×
36
        }
37

38
        table := `|HOST|PORT|USER|PASSWORD|JWT SECRET|POSTGRES VERSION|STATUS|
×
39
|-|-|-|-|-|-|-|
×
40
` + fmt.Sprintf(
×
41
                "|`%s`|`%d`|`%s`|`%s`|`%s`|`%s`|`%s`|\n",
×
42
                detail.DbHost,
×
43
                detail.DbPort,
×
44
                *detail.DbUser,
×
45
                *detail.DbPass,
×
46
                *detail.JwtSecret,
×
47
                detail.PostgresVersion,
×
48
                detail.Status,
×
49
        )
×
50

×
51
        return utils.RenderTable(table)
×
52
}
53

54
func getBranchDetail(ctx context.Context, branchId string) (api.BranchDetailResponse, error) {
×
55
        var result api.BranchDetailResponse
×
56
        if err := uuid.Validate(branchId); err != nil && !utils.ProjectRefPattern.Match([]byte(branchId)) {
×
57
                resp, err := utils.GetSupabase().V1GetABranchWithResponse(ctx, flags.ProjectRef, branchId)
×
58
                if err != nil {
×
59
                        return result, errors.Errorf("failed to find branch: %w", err)
×
60
                } else if resp.JSON200 == nil {
×
61
                        return result, errors.Errorf("unexpected find branch status %d: %s", resp.StatusCode(), string(resp.Body))
×
62
                }
×
63
                branchId = resp.JSON200.ProjectRef
×
64
        }
65
        resp, err := utils.GetSupabase().V1GetABranchConfigWithResponse(ctx, branchId)
×
66
        if err != nil {
×
67
                return result, errors.Errorf("failed to get branch: %w", err)
×
68
        } else if resp.JSON200 == nil {
×
69
                return result, errors.Errorf("unexpected get branch status %d: %s", resp.StatusCode(), string(resp.Body))
×
70
        }
×
71
        masked := "******"
×
72
        if resp.JSON200.DbUser == nil {
×
73
                resp.JSON200.DbUser = &masked
×
74
        }
×
75
        if resp.JSON200.DbPass == nil {
×
76
                resp.JSON200.DbPass = &masked
×
77
        }
×
78
        if resp.JSON200.JwtSecret == nil {
×
79
                resp.JSON200.JwtSecret = &masked
×
80
        }
×
81
        return *resp.JSON200, nil
×
82
}
83

84
func toStandardEnvs(detail api.BranchDetailResponse, pooler api.SupavisorConfigResponse, keys []api.ApiKeyResponse) map[string]string {
×
85
        direct := pgconn.Config{
×
86
                Host:     detail.DbHost,
×
87
                Port:     cast.UIntToUInt16(cast.IntToUint(detail.DbPort)),
×
88
                User:     *detail.DbUser,
×
89
                Password: *detail.DbPass,
×
90
                Database: "postgres",
×
91
        }
×
92
        config, err := utils.ParsePoolerURL(pooler.ConnectionString)
×
93
        if err != nil {
×
94
                fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), err)
×
95
                config = &direct
×
96
        } else {
×
97
                config.Password = direct.Password
×
98
        }
×
99
        envs := apiKeys.ToEnv(keys)
×
100
        envs["POSTGRES_URL"] = utils.ToPostgresURL(*config)
×
101
        envs["POSTGRES_URL_NON_POOLING"] = utils.ToPostgresURL(direct)
×
102
        envs["SUPABASE_URL"] = "https://" + utils.GetSupabaseHost(detail.Ref)
×
103
        envs["SUPABASE_JWT_SECRET"] = *detail.JwtSecret
×
104
        return envs
×
105
}
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