Repository navigation
Replies: 1 comment
|
Keep the binding name One setup is to commit a config template and generate a gitignored // scripts/personal-config.mjs (run from the project root)
import { writeFileSync } from 'node:fs';
const { WORKER_NAME, D1_NAME, D1_ID } = process.env;
if (!WORKER_NAME || !D1_NAME || !D1_ID) {
throw new Error('Set WORKER_NAME, D1_NAME, and D1_ID first');
}
writeFileSync('wrangler.personal.json', JSON.stringify({
name: WORKER_NAME,
main: './worker.js',
compatibility_date: '2026-11-12',
d1_databases: [
{ binding: 'DB', database_name: D1_NAME, database_id: D1_ID },
],
}, null, 2));Use the same config and persistence directory when applying local migrations and starting the Worker: npx wrangler d1 migrations apply DB --local --config wrangler.personal.json --persist-to .wrangler/personal
npx wrangler dev --config wrangler.personal.json --persist-to .wrangler/personalI tested the config selection on Wrangler 4.161.0 with two local UUIDs. I seeded a different row in each local database, and the two |
Uh oh!
There was an error while loading. Please reload this page.
Question:
I’m setting up a Cloudflare Worker with D1 for team development. Each developer will have their own Cloudflare account to deploy/test independently.
Goal:
Developers should override local D1 configs (DB name, ID, etc.) via environment variables (e.g., .dev.vars).
Avoid hardcoding values in wrangler.toml.
Is there any way to achieve this or any other alternatives?
All reactions