diff --git a/internal/db/reset/reset.go b/internal/db/reset/reset.go index 89a33fda5..d53392ae9 100644 --- a/internal/db/reset/reset.go +++ b/internal/db/reset/reset.go @@ -170,8 +170,8 @@ func recreateDatabase(ctx context.Context, options ...func(*pgx.ConnConfig)) err sql := migration.MigrationFile{ Statements: []string{ "DROP DATABASE IF EXISTS postgres WITH (FORCE)", - "DROP DATABASE IF EXISTS _supabase WITH (FORCE)", "CREATE DATABASE postgres WITH OWNER postgres", + "DROP DATABASE IF EXISTS _supabase WITH (FORCE)", "CREATE DATABASE _supabase WITH OWNER postgres", }, } diff --git a/internal/db/reset/reset_test.go b/internal/db/reset/reset_test.go index 03da968c5..ffb9898cf 100644 --- a/internal/db/reset/reset_test.go +++ b/internal/db/reset/reset_test.go @@ -145,6 +145,10 @@ func TestRecreateDatabase(t *testing.T) { Query("DROP DATABASE IF EXISTS postgres WITH (FORCE)"). Reply("DROP DATABASE"). Query("CREATE DATABASE postgres WITH OWNER postgres"). + Reply("CREATE DATABASE"). + Query("DROP DATABASE IF EXISTS _supabase WITH (FORCE)"). + Reply("DROP DATABASE"). + Query("CREATE DATABASE _supabase WITH OWNER postgres"). Reply("CREATE DATABASE") // Run test assert.NoError(t, recreateDatabase(context.Background(), conn.Intercept)) @@ -194,8 +198,11 @@ func TestRecreateDatabase(t *testing.T) { Reply("DO"). Query("DROP DATABASE IF EXISTS postgres WITH (FORCE)"). ReplyError(pgerrcode.ObjectInUse, `database "postgres" is used by an active logical replication slot`). - Query("CREATE DATABASE postgres WITH OWNER postgres") - // Run test + Query("CREATE DATABASE postgres WITH OWNER postgres"). + Query("DROP DATABASE IF EXISTS _supabase WITH (FORCE)"). + Reply("DROP DATABASE"). + Query("CREATE DATABASE _supabase WITH OWNER postgres"). + Reply("CREATE DATABASE") err := recreateDatabase(context.Background(), conn.Intercept) // Check error assert.ErrorContains(t, err, `ERROR: database "postgres" is used by an active logical replication slot (SQLSTATE 55006)`)