Skip to content

Commit 7d8a7df

Browse files
Add scripts to list and delete kv keys in bulk
1 parent 9ef80e3 commit 7d8a7df

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ dist
4848
.dev.vars.*
4949
!.dev.vars.example
5050
!.env*example
51+
*.log

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ After making a change to wrangler.jsonc, you need to run `pnpm cf-typegen` to ge
141141
2. Set either `RESEND_API_KEY` or `BREVO_API_KEY` as a secret in your Cloudflare Worker depending on which email service you want to use.
142142
3. Create a Turnstile catcha in your Cloudflare account, and set the `NEXT_PUBLIC_TURNSTILE_SITE_KEY` as a Github Actions variable.
143143
4. Set `TURNSTILE_SECRET_KEY` as a secret in your Cloudflare Worker.
144-
5. Update the `wrangler.jsonc` file with the new database and KV namespaces and env variables. Search for "cloudflare-workers-nextjs-saas-template" recursively in the whole repository and change that to the name of your project. Don't forget that the name you choose at the top of the wrangler.jsonc should be the same as `services->[0]->service` in the same file.
144+
5. Update the `wrangler.jsonc` file with the new database and KV namespaces, env variables and account id. Search for "cloudflare-workers-nextjs-saas-template" recursively in the whole repository and change that to the name of your project. Don't forget that the name you choose at the top of the wrangler.jsonc should be the same as `services->[0]->service` in the same file.
145145
6. Go to https://dash.cloudflare.com/profile/api-tokens and click on "Use template" next to "Edit Cloudflare Workers". On the next, page add the following permissions in addition to the ones from the template:
146146
- Account:AI Gateway:Edit
147147
- Account:Workers AI:Edit

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"db:migrate:dev": "wrangler d1 migrations apply $(node scripts/get-db-name.mjs) --local",
1818
"d1:cache:clean": "wrangler d1 execute $(node scripts/get-db-name.mjs) --command \"DELETE FROM tags; DELETE FROM revalidations\" --remote",
1919
"d1:cache:seed": "wrangler d1 execute $(node scripts/get-db-name.mjs) --file .open-next/cloudflare/cache-assets-manifest.sql --remote",
20-
"email:dev": "email dev -d src/react-email -p 3001"
20+
"email:dev": "email dev -d src/react-email -p 3001",
21+
"list:kv": "wrangler kv key list --namespace-id=$(node scripts/get-kv-id.mjs) --remote | jq '[.[].name]' > kv.log",
22+
"delete:kv": "wrangler kv bulk delete kv.log --namespace-id=$(node scripts/get-kv-id.mjs) --remote"
2123
},
2224
"dependencies": {
2325
"@heroicons/react": "^2.2.0",

scripts/get-kv-id.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { parseWranglerConfig } from './utils/parse-wrangler.mjs';
2+
3+
try {
4+
const config = parseWranglerConfig();
5+
const kvId = config.kv_namespaces?.[0]?.id;
6+
7+
if (!kvId) {
8+
console.error('KV namespace ID not found in wrangler.jsonc');
9+
process.exit(1);
10+
}
11+
12+
console.log(kvId);
13+
} catch (error) {
14+
console.error(error.message);
15+
process.exit(1);
16+
}

wrangler.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
{
66
"$schema": "node_modules/wrangler/config-schema.json",
7+
"account_id": "82e5aa3e06eba55221231ef482269452",
78
"name": "cloudflare-workers-nextjs-saas-template",
89
"main": ".open-next/worker.js",
910
"compatibility_date": "2024-09-26",

0 commit comments

Comments
 (0)