Skip to content

Commit 05d91ef

Browse files
fix: use static list of project regions (#4692)
* fix: load profile before initializing awsRegions * chore: minor refactor * chore: reuse region flag * chore: remove unused region method * fix: set default profile without loading --------- Co-authored-by: Han Qiao <[email protected]> Co-authored-by: Qiao Han <[email protected]>
1 parent 11fea2e commit 05d91ef

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

cmd/branches.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ var (
3030
Short: "Manage Supabase preview branches",
3131
}
3232

33-
branchRegion = utils.EnumFlag{
34-
Allowed: awsRegions(),
35-
}
3633
persistent bool
3734
withData bool
3835
notifyURL string
@@ -49,7 +46,7 @@ var (
4946
}
5047
cmdFlags := cmd.Flags()
5148
if cmdFlags.Changed("region") {
52-
body.Region = &branchRegion.Value
49+
body.Region = &region.Value
5350
}
5451
if cmdFlags.Changed("size") {
5552
body.DesiredInstanceSize = (*api.CreateBranchBodyDesiredInstanceSize)(&size.Value)
@@ -206,7 +203,7 @@ func init() {
206203
branchFlags := branchesCmd.PersistentFlags()
207204
branchFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
208205
createFlags := branchCreateCmd.Flags()
209-
createFlags.Var(&branchRegion, "region", "Select a region to deploy the branch database.")
206+
createFlags.Var(&region, "region", "Select a region to deploy the branch database.")
210207
createFlags.Var(&size, "size", "Select a desired instance size for the branch database.")
211208
createFlags.BoolVar(&persistent, "persistent", false, "Whether to create a persistent branch.")
212209
createFlags.BoolVar(&withData, "with-data", false, "Whether to clone production data to the branch database.")

cmd/projects.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"os"
5-
"sort"
65

76
"github.com/spf13/afero"
87
"github.com/spf13/cobra"
@@ -30,7 +29,7 @@ var (
3029
orgId string
3130
dbPassword string
3231
region = utils.EnumFlag{
33-
Allowed: awsRegions(),
32+
Allowed: utils.AwsRegions(),
3433
}
3534
size = utils.EnumFlag{
3635
Allowed: []string{
@@ -153,12 +152,3 @@ func init() {
153152
projectsCmd.AddCommand(projectsApiKeysCmd)
154153
rootCmd.AddCommand(projectsCmd)
155154
}
156-
157-
func awsRegions() []string {
158-
result := make([]string, len(utils.CurrentProfile.ProjectRegions))
159-
for i, region := range utils.CurrentProfile.ProjectRegions {
160-
result[i] = string(region)
161-
}
162-
sort.Strings(result)
163-
return result
164-
}

internal/utils/profile.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"context"
55
"fmt"
6+
"sort"
67
"strings"
78

89
"github.com/go-errors/errors"
@@ -128,3 +129,12 @@ func getProfileName(fsys afero.Fs) string {
128129
return prof
129130
}
130131
}
132+
133+
func AwsRegions() []string {
134+
result := make([]string, len(allProfiles[0].ProjectRegions))
135+
for i, region := range allProfiles[0].ProjectRegions {
136+
result[i] = string(region)
137+
}
138+
sort.Strings(result)
139+
return result
140+
}

0 commit comments

Comments
 (0)