Repository: supabase/cli
Pull request #2192 (2024-04-19 12:51:27)

fix: defaults to no when confirming delete operations
## What kind of change does this PR introduce?

Bug fix: https://github.com/supabase/cli/issues/1875

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.



Patch:
diff --git a/go.mod b/go.mod
index db947a1e..e806ef20 100644
--- a/go.mod
+++ b/go.mod
@@ -323,7 +323,7 @@ require (
 	golang.org/x/crypto v0.21.0 // indirect
 	golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
 	golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
-	golang.org/x/net v0.22.0 // indirect
+	golang.org/x/net v0.23.0 // indirect
 	golang.org/x/sync v0.6.0 // indirect
 	golang.org/x/sys v0.19.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
diff --git a/go.sum b/go.sum
index a3aa34dd..40f1c6bd 100644
--- a/go.sum
+++ b/go.sum
@@ -1188,8 +1188,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
 golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
 golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
 golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
-golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
-golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
+golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
+golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
diff --git a/internal/db/reset/reset.go b/internal/db/reset/reset.go
index 38219c57..a6311dc3 100644
--- a/internal/db/reset/reset.go
+++ b/internal/db/reset/reset.go
@@ -51,7 +51,7 @@ func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.F
 	}
 	if !utils.IsLocalDatabase(config) {
 		msg := "Do you want to reset the remote database?"
-		if shouldReset := utils.NewConsole().PromptYesNo(msg, true); !shouldReset {
+		if shouldReset := utils.NewConsole().PromptYesNo(msg, false); !shouldReset {
 			utils.CmdSuggestion = ""
 			return errors.New(context.Canceled)
 		}
diff --git a/internal/db/reset/templates/drop.sql b/internal/db/reset/templates/drop.sql
index 031357dc..fa44da33 100644
--- a/internal/db/reset/templates/drop.sql
+++ b/internal/db/reset/templates/drop.sql
@@ -33,6 +33,17 @@ begin
     execute format('drop table if exists %I.%I cascade', rec.relnamespace::regnamespace::name, rec.relname);
   end loop;
 
+  -- truncate auth tables
+  for rec in
+    select *
+    from pg_class c
+    where
+      c.relnamespace::regnamespace::name = 'auth'
+      and c.relkind = 'r'
+  loop
+    execute format('truncate %I.%I restart identity cascade', rec.relnamespace::regnamespace::name, rec.relname);
+  end loop;
+
   -- sequences
   for rec in
     select *
diff --git a/internal/projects/delete/delete.go b/internal/projects/delete/delete.go
index 7692b457..616afcbf 100644
--- a/internal/projects/delete/delete.go
+++ b/internal/projects/delete/delete.go
@@ -17,7 +17,8 @@ func PreRun(ref string) error {
 	if err := utils.AssertProjectRefIsValid(ref); err != nil {
 		return err
 	}
-	if !utils.NewConsole().PromptYesNo("Do you want to delete project "+utils.Aqua(ref)+"? This action is irreversible.", true) {
+	title := fmt.Sprintf("Do you want to delete project %s? This action is irreversible.", utils.Aqua(ref))
+	if shouldDelete := utils.NewConsole().PromptYesNo(title, false); !shouldDelete {
 		return errors.New("Not deleting project: " + utils.Aqua(ref))
 	}
 	return nil
diff --git a/internal/storage/rm/rm.go b/internal/storage/rm/rm.go
index 6553c423..6b788358 100644
--- a/internal/storage/rm/rm.go
+++ b/internal/storage/rm/rm.go
@@ -51,7 +51,7 @@ func Run(ctx context.Context, paths []string, recursive bool, fsys afero.Fs) err
 	}
 	for bucket, prefixes := range groups {
 		confirm := fmt.Sprintf("Confirm deleting files in bucket %v?", utils.Bold(bucket))
-		if shouldDelete := utils.NewConsole().PromptYesNo(confirm, true); !shouldDelete {
+		if shouldDelete := utils.NewConsole().PromptYesNo(confirm, false); !shouldDelete {
 			continue
 		}
 		// Always try deleting first in case the paths resolve to extensionless files


Test patch:
diff --git a/internal/db/reset/reset_test.go b/internal/db/reset/reset_test.go
index cbeecb93..6841dbf4 100644
--- a/internal/db/reset/reset_test.go
+++ b/internal/db/reset/reset_test.go
@@ -17,6 +17,7 @@ import (
 	"github.com/stretchr/testify/require"
 	"github.com/supabase/cli/internal/db/start"
 	"github.com/supabase/cli/internal/testing/apitest"
+	"github.com/supabase/cli/internal/testing/fstest"
 	"github.com/supabase/cli/internal/testing/pgtest"
 	"github.com/supabase/cli/internal/utils"
 	"gopkg.in/h2non/gock.v1"
@@ -35,6 +36,16 @@ func TestResetCommand(t *testing.T) {
 	}
 
 	t.Run("throws error on context canceled", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		// Run test
+		err := Run(context.Background(), "", pgconn.Config{Host: "db.supabase.co"}, fsys)
+		// Check error
+		assert.ErrorIs(t, err, context.Canceled)
+	})
+
+	t.Run("throws error on invalid port", func(t *testing.T) {
+		defer fstest.MockStdin(t, "y")()
 		// Setup in-memory fs
 		fsys := afero.NewMemMapFs()
 		// Run test
diff --git a/internal/storage/rm/rm_test.go b/internal/storage/rm/rm_test.go
index 49d4e3da..b56b77ca 100644
--- a/internal/storage/rm/rm_test.go
+++ b/internal/storage/rm/rm_test.go
@@ -10,6 +10,7 @@ import (
 	"github.com/stretchr/testify/require"
 	"github.com/supabase/cli/internal/storage/client"
 	"github.com/supabase/cli/internal/testing/apitest"
+	"github.com/supabase/cli/internal/testing/fstest"
 	"github.com/supabase/cli/internal/utils"
 	"github.com/supabase/cli/pkg/api"
 	"gopkg.in/h2non/gock.v1"
@@ -70,6 +71,7 @@ func TestStorageRM(t *testing.T) {
 	})
 
 	t.Run("removes multiple objects", func(t *testing.T) {
+		defer fstest.MockStdin(t, "y")()
 		// Setup in-memory fs
 		fsys := afero.NewMemMapFs()
 		projectRef := apitest.RandomProjectRef()
@@ -113,6 +115,7 @@ func TestStorageRM(t *testing.T) {
 	})
 
 	t.Run("removes buckets and directories", func(t *testing.T) {
+		defer fstest.MockStdin(t, "y")()
 		// Setup in-memory fs
 		fsys := afero.NewMemMapFs()
 		projectRef := apitest.RandomProjectRef()
@@ -187,6 +190,7 @@ func TestStorageRM(t *testing.T) {
 	})
 
 	t.Run("throws error on delete failure", func(t *testing.T) {
+		defer fstest.MockStdin(t, "y")()
 		// Setup in-memory fs
 		fsys := afero.NewMemMapFs()
 		projectRef := apitest.RandomProjectRef()