feat: check project status at link time (#2730) · pathob/supabase-cli@ce26abd · GitHub
Skip to content

Commit ce26abd

Browse files
authored
feat: check project status at link time (supabase#2730)
* feat: check project status at link time * fix: link color * fix: testing * chore: use get project endpoint * chore: apply review suggestions
1 parent 52dfb4d commit ce26abd

4 files changed

Lines changed: 193 additions & 0 deletions

File tree

‎api/beta.yaml‎

Lines changed: 25 additions & 0 deletions

‎internal/link/link.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs, options ...func(
2929
"api": utils.Config.Api,
3030
"db": utils.Config.Db,
3131
})
32+
33+
if err := checkRemoteProjectStatus(ctx, projectRef); err != nil {
34+
return err
35+
}
36+
3237
// 1. Check service config
3338
keys, err := tenant.GetApiKeys(ctx, projectRef)
3439
if err != nil {
@@ -236,3 +241,26 @@ func updatePoolerConfig(config api.SupavisorConfigResponse) {
236241
utils.Config.Db.Pooler.MaxClientConn = uint(*config.MaxClientConn)
237242
}
238243
}
244+
245+
func checkRemoteProjectStatus(ctx context.Context, projectRef string) error {
246+
resp, err := utils.GetSupabase().V1GetProjectWithResponse(ctx, projectRef)
247+
if err != nil {
248+
return errors.Errorf("failed to retrieve remote project status: %w", err)
249+
}
250+
if resp.JSON200 == nil {
251+
return errors.New("Unexpected error retrieving remote project status: " + string(resp.Body))
252+
}
253+
254+
switch resp.JSON200.Status {
255+
case api.V1ProjectResponseStatusINACTIVE:
256+
utils.CmdSuggestion = fmt.Sprintf("An admin must unpause it from the Supabase dashboard at %s", utils.Aqua(fmt.Sprintf("%s/project/%s", utils.GetSupabaseDashboardURL(), projectRef)))
257+
return errors.New("project is paused")
258+
case api.V1ProjectResponseStatusACTIVEHEALTHY:
259+
// Project is in the desired state, do nothing
260+
return nil
261+
default:
262+
fmt.Fprintf(os.Stderr, "%s: Project status is %s instead of Active Healthy. Some operations might fail.\n", utils.Yellow("Warning"), resp.JSON200.Status)
263+
}
264+
265+
return nil
266+
}

‎internal/link/link_test.go‎

Lines changed: 31 additions & 0 deletions

‎pkg/api/client.gen.go‎

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)