From b79edafd1eda36c9492587d415d23055323fa012 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Tue, 9 Dec 2025 13:31:31 +0800 Subject: [PATCH] fix: scope project region by current profile --- cmd/projects.go | 8 ++--- internal/projects/create/create.go | 11 ++++--- internal/utils/api.go | 17 ---------- internal/utils/profile.go | 51 +++++++++++++++++++++++++----- internal/utils/render.go | 23 +++++++++++++- 5 files changed, 74 insertions(+), 36 deletions(-) diff --git a/cmd/projects.go b/cmd/projects.go index 297ed5853..2ab5d7d2d 100644 --- a/cmd/projects.go +++ b/cmd/projects.go @@ -155,11 +155,9 @@ func init() { } func awsRegions() []string { - result := make([]string, len(utils.RegionMap)) - i := 0 - for k := range utils.RegionMap { - result[i] = k - i++ + result := make([]string, len(utils.CurrentProfile.ProjectRegions)) + for i, region := range utils.CurrentProfile.ProjectRegions { + result[i] = string(region) } sort.Strings(result) return result diff --git a/internal/projects/create/create.go b/internal/projects/create/create.go index 10bd5a460..98b042335 100644 --- a/internal/projects/create/create.go +++ b/internal/projects/create/create.go @@ -116,11 +116,12 @@ func promptOrgId(ctx context.Context) (string, error) { func promptProjectRegion(ctx context.Context) (api.V1CreateProjectBodyRegion, error) { title := "Which region do you want to host the project in?" - items := make([]utils.PromptItem, len(utils.RegionMap)) - i := 0 - for k, v := range utils.RegionMap { - items[i] = utils.PromptItem{Summary: k, Details: v} - i++ + items := make([]utils.PromptItem, len(utils.CurrentProfile.ProjectRegions)) + for i, region := range utils.CurrentProfile.ProjectRegions { + items[i] = utils.PromptItem{ + Summary: string(region), + Details: utils.FormatRegion(string(region)), + } } choice, err := utils.PromptChoice(ctx, title, items) if err != nil { diff --git a/internal/utils/api.go b/internal/utils/api.go index 3cc1dd380..5b9a96fde 100644 --- a/internal/utils/api.go +++ b/internal/utils/api.go @@ -141,23 +141,6 @@ func GetSupabase() *supabase.ClientWithResponses { // Used by unit tests var DefaultApiHost = CurrentProfile.APIURL -var RegionMap = map[string]string{ - "ap-northeast-1": "Northeast Asia (Tokyo)", - "ap-northeast-2": "Northeast Asia (Seoul)", - "ap-south-1": "South Asia (Mumbai)", - "ap-southeast-1": "Southeast Asia (Singapore)", - "ap-southeast-2": "Oceania (Sydney)", - "ca-central-1": "Canada (Central)", - "eu-central-1": "Central EU (Frankfurt)", - "eu-west-1": "West EU (Ireland)", - "eu-west-2": "West EU (London)", - "eu-west-3": "West EU (Paris)", - "sa-east-1": "South America (São Paulo)", - "us-east-1": "East US (North Virginia)", - "us-west-1": "West US (North California)", - "us-west-2": "West US (Oregon)", -} - func GetSupabaseAPIHost() string { return CurrentProfile.APIURL } diff --git a/internal/utils/profile.go b/internal/utils/profile.go index fcb089e3f..1910f30b7 100644 --- a/internal/utils/profile.go +++ b/internal/utils/profile.go @@ -9,17 +9,19 @@ import ( "github.com/go-playground/validator/v10" "github.com/spf13/afero" "github.com/spf13/viper" + "github.com/supabase/cli/pkg/api" ) type Profile struct { - Name string `mapstructure:"name" validate:"required"` - APIURL string `mapstructure:"api_url" validate:"required,http_url"` - DashboardURL string `mapstructure:"dashboard_url" validate:"required,http_url"` - DocsURL string `mapstructure:"docs_url" validate:"omitempty,http_url"` - ProjectHost string `mapstructure:"project_host" validate:"required,hostname_rfc1123"` - PoolerHost string `mapstructure:"pooler_host" validate:"omitempty,hostname_rfc1123"` - AuthClientID string `mapstructure:"client_id" validate:"omitempty,uuid4"` - StudioImage string `mapstructure:"studio_image"` + Name string `mapstructure:"name" validate:"required"` + APIURL string `mapstructure:"api_url" validate:"required,http_url"` + DashboardURL string `mapstructure:"dashboard_url" validate:"required,http_url"` + DocsURL string `mapstructure:"docs_url" validate:"omitempty,http_url"` + ProjectHost string `mapstructure:"project_host" validate:"required,hostname_rfc1123"` + PoolerHost string `mapstructure:"pooler_host" validate:"omitempty,hostname_rfc1123"` + AuthClientID string `mapstructure:"client_id" validate:"omitempty,uuid4"` + StudioImage string `mapstructure:"studio_image"` + ProjectRegions []api.V1CreateProjectBodyRegion `mapstructure:"regions"` } var allProfiles = []Profile{{ @@ -29,6 +31,26 @@ var allProfiles = []Profile{{ DocsURL: "https://supabase.com/docs", ProjectHost: "supabase.co", PoolerHost: "supabase.com", + ProjectRegions: []api.V1CreateProjectBodyRegion{ + api.V1CreateProjectBodyRegionApEast1, + api.V1CreateProjectBodyRegionApNortheast1, + api.V1CreateProjectBodyRegionApNortheast2, + api.V1CreateProjectBodyRegionApSouth1, + api.V1CreateProjectBodyRegionApSoutheast1, + api.V1CreateProjectBodyRegionApSoutheast2, + api.V1CreateProjectBodyRegionCaCentral1, + api.V1CreateProjectBodyRegionEuCentral1, + api.V1CreateProjectBodyRegionEuCentral2, + api.V1CreateProjectBodyRegionEuNorth1, + api.V1CreateProjectBodyRegionEuWest1, + api.V1CreateProjectBodyRegionEuWest2, + api.V1CreateProjectBodyRegionEuWest3, + api.V1CreateProjectBodyRegionSaEast1, + api.V1CreateProjectBodyRegionUsEast1, + api.V1CreateProjectBodyRegionUsEast2, + api.V1CreateProjectBodyRegionUsWest1, + api.V1CreateProjectBodyRegionUsWest2, + }, }, { Name: "supabase-staging", APIURL: "https://api.supabase.green", @@ -36,12 +58,22 @@ var allProfiles = []Profile{{ DocsURL: "https://supabase.com/docs", ProjectHost: "supabase.red", PoolerHost: "supabase.green", + ProjectRegions: []api.V1CreateProjectBodyRegion{ + api.V1CreateProjectBodyRegionApSoutheast1, + api.V1CreateProjectBodyRegionUsEast1, + api.V1CreateProjectBodyRegionEuCentral1, + }, }, { Name: "supabase-local", APIURL: "http://localhost:8080", DashboardURL: "http://localhost:8082", DocsURL: "https://supabase.com/docs", ProjectHost: "supabase.red", + ProjectRegions: []api.V1CreateProjectBodyRegion{ + api.V1CreateProjectBodyRegionApSoutheast1, + api.V1CreateProjectBodyRegionUsEast1, + api.V1CreateProjectBodyRegionEuCentral1, + }, }, { Name: "snap", APIURL: "https://cloudapi.snap.com", @@ -50,6 +82,9 @@ var allProfiles = []Profile{{ ProjectHost: "snapcloud.dev", PoolerHost: "snapcloud.co", AuthClientID: "f7573b20-df47-48f1-b606-e8db4ec16252", + ProjectRegions: []api.V1CreateProjectBodyRegion{ + api.V1CreateProjectBodyRegionUsEast1, + }, }} var CurrentProfile Profile diff --git a/internal/utils/render.go b/internal/utils/render.go index 07d674d29..ee4a4dc6c 100644 --- a/internal/utils/render.go +++ b/internal/utils/render.go @@ -31,8 +31,29 @@ func parse(layout, value string) string { return FormatTime(t) } +var regionMap = map[string]string{ + "ap-east-1": "East Asia (Hong Kong)", + "ap-northeast-1": "Northeast Asia (Tokyo)", + "ap-northeast-2": "Northeast Asia (Seoul)", + "ap-south-1": "South Asia (Mumbai)", + "ap-southeast-1": "Southeast Asia (Singapore)", + "ap-southeast-2": "Oceania (Sydney)", + "ca-central-1": "Canada (Central)", + "eu-central-1": "Central EU (Frankfurt)", + "eu-central-2": "Central Europe (Zurich)", + "eu-north-1": "North EU (Stockholm)", + "eu-west-1": "West EU (Ireland)", + "eu-west-2": "West Europe (London)", + "eu-west-3": "West EU (Paris)", + "sa-east-1": "South America (São Paulo)", + "us-east-1": "East US (North Virginia)", + "us-east-2": "East US (Ohio)", + "us-west-1": "West US (North California)", + "us-west-2": "West US (Oregon)", +} + func FormatRegion(region string) string { - if readable, ok := RegionMap[region]; ok { + if readable, ok := regionMap[region]; ok { return readable } return region