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

supabase / cli / 18438581361

12 Oct 2025 03:31AM UTC coverage: 54.641% (-0.06%) from 54.701%
18438581361

Pull #4293

github

web-flow
Merge fb164500a into 4785f7a63
Pull Request #4293: chore: bump openapi spec and overlay

1 of 6 new or added lines in 2 files covered. (16.67%)

8 existing lines in 2 files now uncovered.

6405 of 11722 relevant lines covered (54.64%)

6.09 hits per line

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

42.16
/internal/projects/create/create.go
1
package create
2

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

9
        "github.com/go-errors/errors"
10
        "github.com/spf13/afero"
11
        "github.com/spf13/viper"
12
        "github.com/supabase/cli/internal/utils"
13
        "github.com/supabase/cli/internal/utils/credentials"
14
        "github.com/supabase/cli/internal/utils/flags"
15
        "github.com/supabase/cli/pkg/api"
16
)
17

18
func Run(ctx context.Context, params api.V1CreateProjectBody, fsys afero.Fs) error {
5✔
19
        if err := promptMissingParams(ctx, &params); err != nil {
5✔
20
                return err
×
21
        }
×
22

23
        resp, err := utils.GetSupabase().V1CreateAProjectWithResponse(ctx, params)
5✔
24
        if err != nil {
7✔
25
                return errors.Errorf("failed to create project: %w", err)
2✔
26
        }
2✔
27
        if resp.JSON201 == nil {
5✔
28
                return errors.New("Unexpected error creating project: " + string(resp.Body))
2✔
29
        }
2✔
30

31
        flags.ProjectRef = resp.JSON201.Id
1✔
32
        viper.Set("DB_PASSWORD", params.DbPass)
1✔
33
        if err := credentials.StoreProvider.Set(flags.ProjectRef, params.DbPass); err != nil {
1✔
34
                fmt.Fprintln(os.Stderr, "Failed to save database password:", err)
×
35
        }
×
36

37
        projectUrl := fmt.Sprintf("%s/project/%s", utils.GetSupabaseDashboardURL(), resp.JSON201.Id)
1✔
38
        fmt.Fprintf(os.Stderr, "Created a new project at %s\n", utils.Bold(projectUrl))
1✔
39
        if utils.OutputFormat.Value == utils.OutputPretty {
2✔
40
                table := `|ORG ID|REFERENCE ID|NAME|REGION|CREATED AT (UTC)|
1✔
41
|-|-|-|-|-|
1✔
42
`
1✔
43
                table += fmt.Sprintf(
1✔
44
                        "|`%s`|`%s`|`%s`|`%s`|`%s`|\n",
1✔
45
                        resp.JSON201.OrganizationId,
1✔
46
                        resp.JSON201.Id,
1✔
47
                        strings.ReplaceAll(resp.JSON201.Name, "|", "\\|"),
1✔
48
                        utils.FormatRegion(resp.JSON201.Region),
1✔
49
                        utils.FormatTimestamp(resp.JSON201.CreatedAt),
1✔
50
                )
1✔
51
                return utils.RenderTable(table)
1✔
52
        }
1✔
53
        return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, resp.JSON201)
×
54
}
55

56
func printKeyValue(key, value string) string {
5✔
57
        indent := 20 - len(key)
5✔
58
        spaces := strings.Repeat(" ", indent)
5✔
59
        return key + ":" + spaces + value
5✔
60
}
5✔
61

62
func promptMissingParams(ctx context.Context, body *api.V1CreateProjectBody) error {
5✔
63
        var err error
5✔
64
        if len(body.Name) == 0 {
5✔
65
                if body.Name, err = promptProjectName(ctx); err != nil {
×
66
                        return err
×
67
                }
×
68
        } else {
5✔
69
                fmt.Fprintln(os.Stderr, printKeyValue("Creating project", body.Name))
5✔
70
        }
5✔
71
        if len(body.OrganizationId) == 0 {
5✔
72
                if body.OrganizationId, err = promptOrgId(ctx); err != nil {
×
73
                        return err
×
74
                }
×
75
                fmt.Fprintln(os.Stderr, printKeyValue("Selected org-id", body.OrganizationId))
×
76
        }
77
        if body.Region == nil || len(*body.Region) == 0 {
5✔
NEW
78
                region, err := promptProjectRegion(ctx)
×
NEW
79
                if err != nil {
×
80
                        return err
×
81
                }
×
NEW
82
                body.Region = &region
×
NEW
83
                fmt.Fprintln(os.Stderr, printKeyValue("Selected region", string(region)))
×
84
        }
85
        if len(body.DbPass) == 0 {
5✔
86
                body.DbPass = flags.PromptPassword(os.Stdin)
×
87
        }
×
88
        return nil
5✔
89
}
90

91
func promptProjectName(ctx context.Context) (string, error) {
×
92
        title := "Enter your project name: "
×
93
        if name, err := utils.NewConsole().PromptText(ctx, title); err != nil {
×
94
                return "", err
×
95
        } else if len(name) > 0 {
×
96
                return name, nil
×
97
        }
×
98
        return "", errors.New("project name cannot be empty")
×
99
}
100

101
func promptOrgId(ctx context.Context) (string, error) {
×
102
        title := "Which organisation do you want to create the project for?"
×
103
        resp, err := utils.GetSupabase().V1ListAllOrganizationsWithResponse(ctx)
×
104
        if err != nil {
×
105
                return "", err
×
106
        }
×
107
        if resp.JSON200 == nil {
×
108
                return "", errors.New("Unexpected error retrieving organizations: " + string(resp.Body))
×
109
        }
×
110
        items := make([]utils.PromptItem, len(*resp.JSON200))
×
111
        for i, org := range *resp.JSON200 {
×
112
                items[i] = utils.PromptItem{Summary: org.Name, Details: org.Id}
×
113
        }
×
114
        choice, err := utils.PromptChoice(ctx, title, items)
×
115
        if err != nil {
×
116
                return "", err
×
117
        }
×
118
        return choice.Details, nil
×
119
}
120

121
func promptProjectRegion(ctx context.Context) (api.V1CreateProjectBodyRegion, error) {
×
122
        title := "Which region do you want to host the project in?"
×
123
        items := make([]utils.PromptItem, len(utils.RegionMap))
×
124
        i := 0
×
125
        for k, v := range utils.RegionMap {
×
126
                items[i] = utils.PromptItem{Summary: k, Details: v}
×
127
                i++
×
128
        }
×
129
        choice, err := utils.PromptChoice(ctx, title, items)
×
130
        if err != nil {
×
131
                return "", err
×
132
        }
×
133
        return api.V1CreateProjectBodyRegion(choice.Summary), nil
×
134
}
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