-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the output format of wrangler kv:key list --namespace-id
command
#2620
Comments
Hey! 馃憢 I've moved this issue over from the legacy |
I would just like to see Currently:
outputs objects in array like [
{
"name": "1705463215143/1705463215143250391365196660"
}
]
outputs errors:
I can manually fix them, but it would be nice if it worked with the same format it outputs. |
Wow guys, this issue is still here at 2024. So just like me you want to bulk delete all the keys from a KV namespace using Wrangler. Here is how to do it: List all the KV namespaces associated with the account: wrangler kv:namespace list List all the keys from the given namespace and save them to a file: wrangler kv:key list --namespace-id=string_of_numbers > raw_keys.json Use this Bash script to convert the generated file into a format that can be fed to the bulk delete command:
chmod +x script.sh Finally delete all the keys from the namespace: wrangler kv:bulk delete --namespace-id=string_of_numbers keys_for_deletion.json Hope this comes handy to someone :) |
For anyone else looking for a simpler solution, you can transform the format using just
|
馃挕 Feature request
In a nutshell: improve how
kv list
andkv bulk delete
commands work together. I'd like to get a list of names in KV so that I can then run a wrangler command to perform a bulk delete. However the format of thekv list
output is not what is accepted when running thekv bulk delete
command.Describe the feature
Current behaviour
When running the command
wrangler kv:key list --namespace-id=someID
the result will output an array of objects with the following:Desired feature
Can you add a flag to the command such that the results are formatted in a way that makes it easy to do a bulk delete, as required in the CloudFlare docs. For example:
Desired command
wrangler kv:key list --namespace-id=someID --deleteHelper
Desired output
If I run the
kv:bulk delete
command using the output fromwrangler kv:key list --namespace-id=someID
I get the following error:Error: Failed to decode JSON. Please make sure to follow the format, [{"key": "test_key", "value": "test_value"}, ...]
As you can see, the
list
anddelete
commands have different outputs which make it impossible to run the following:wrangler kv:key list --namespace-id=${namespaceID} > PURGE.json
wrangler kv:bulk delete --namespace-id=${namespaceID} PURGE.json
Note
It is not necessary to return the actual values of each key. It is sufficient to just include "value":"" for the bulk delete command to work.
The other solution would be to update the
kv:bulk delete
command such that it accepts the current output ofwrangler kv:key list --namespace-id=someID
.Describe the alternatives
Are there any alternatives to solving this problem? If so, what was your experience with them?
The way I am getting around this issue is quite tedious and manual. Currently I'm running the command:
wrangler kv:key list --namespace-id=${namespaceID} > PURGE.json
And then I am doing a find + replace command inside PURGE.json so that:
1- anywhere there is "name" it is replaced with "key"
2- and in order to insert the
"value": ""
bit that is required, I then search for:"},
and replace it with
"", "value": ""},
And finally I am able to get the correct format required for bulk deletion.
The text was updated successfully, but these errors were encountered: