diff --git a/internal/db/reset/reset.go b/internal/db/reset/reset.go index be4802fb7..8369fd389 100644 --- a/internal/db/reset/reset.go +++ b/internal/db/reset/reset.go @@ -54,11 +54,13 @@ func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.F return err } // Seed objects from supabase/buckets directory - if err := start.WaitForHealthyService(ctx, 30*time.Second, utils.StorageId); err != nil { - return err - } - if err := buckets.Run(ctx, "", false, fsys); err != nil { - return err + if utils.Config.Storage.Enabled { + if err := start.WaitForHealthyService(ctx, 30*time.Second, utils.StorageId); err != nil { + return err + } + if err := buckets.Run(ctx, "", false, fsys); err != nil { + return err + } } branch := keys.GetGitBranch(fsys) fmt.Fprintln(os.Stderr, "Finished "+utils.Aqua("supabase db reset")+" on branch "+utils.Aqua(branch)+".") @@ -204,8 +206,11 @@ func RestartDatabase(ctx context.Context, w io.Writer) error { } func restartServices(ctx context.Context) error { + debug := utils.GetDebugLogger() // No need to restart PostgREST because it automatically reconnects and listens for schema changes services := listServicesToRestart() + fmt.Fprintf(debug, "Enabled services to restart: %v\n", services) + result := utils.WaitAll(services, func(id string) error { if err := utils.Docker.ContainerRestart(ctx, id, container.StopOptions{}); err != nil && !errdefs.IsNotFound(err) { return errors.Errorf("Failed to restart %s: %w", id, err) @@ -217,7 +222,22 @@ func restartServices(ctx context.Context) error { } func listServicesToRestart() []string { - return []string{utils.StorageId, utils.GotrueId, utils.RealtimeId, utils.PoolerId} + var services []string + + if utils.Config.Storage.Enabled { + services = append(services, utils.StorageId) + } + if utils.Config.Realtime.Enabled { + services = append(services, utils.RealtimeId) + } + if utils.Config.Db.Pooler.Enabled { + services = append(services, utils.PoolerId) + } + if utils.Config.Auth.Enabled { + services = append(services, utils.GotrueId) + } + + return services } func resetRemote(ctx context.Context, version string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { diff --git a/internal/db/reset/reset_test.go b/internal/db/reset/reset_test.go index 38fef4b96..d5576ad82 100644 --- a/internal/db/reset/reset_test.go +++ b/internal/db/reset/reset_test.go @@ -321,6 +321,44 @@ func TestRestartDatabase(t *testing.T) { assert.ErrorContains(t, err, "test-reset container is not running: exited") assert.Empty(t, apitest.ListUnmatchedRequests()) }) + t.Run("restarts only enabled services", func(t *testing.T) { + utils.DbId = "test-reset" + utils.Config.Storage.Enabled = false + utils.Config.Auth.Enabled = true + utils.Config.Realtime.Enabled = true + utils.Config.Db.Pooler.Enabled = false + // Setup mock docker + require.NoError(t, apitest.MockDocker(utils.Docker)) + defer gock.OffAll() + // Restarts postgres + gock.New(utils.Docker.DaemonHost()). + Post("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.DbId + "/restart"). + Reply(http.StatusOK) + gock.New(utils.Docker.DaemonHost()). + Get("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.DbId + "/json"). + Reply(http.StatusOK). + JSON(types.ContainerJSON{ContainerJSONBase: &types.ContainerJSONBase{ + State: &types.ContainerState{ + Running: true, + Health: &types.Health{Status: "healthy"}, + }, + }}) + // Restarts enabled services + utils.StorageId = "test-storage" + utils.PoolerId = "test-pooler" + utils.GotrueId = "test-auth" + utils.RealtimeId = "test-realtime" + for _, container := range []string{utils.GotrueId, utils.RealtimeId} { + gock.New(utils.Docker.DaemonHost()). + Post("/v" + utils.Docker.ClientVersion() + "/containers/" + container + "/restart"). + Reply(http.StatusOK) + } + // Run test + err := RestartDatabase(context.Background(), io.Discard) + // Check error + assert.NoError(t, err) + assert.Empty(t, apitest.ListUnmatchedRequests()) + }) } var escapedSchemas = append(migration.ManagedSchemas, "extensions", "public")