Deploy, Monitor and Fix
Ship It So You Can Un-Ship It
The Order Matters
npx wrangler secret put WEBHOOK_SECRET # secrets go here, never in config
npx wrangler d1 migrations apply my-db --local # try the migration here first
npx wrangler deploy --dry-run # builds and lists bindings, ships nothing
npx wrangler d1 migrations apply my-db --remote # change the real database
npx wrangler deploy # ship it
npx wrangler tail --status error # watch for errors, live
Database before code, because the new code usually needs the new column. That only works if the old code survives the change too. Adding a column is safe. Renaming or dropping one breaks whatever is live right now, so do it in two steps: ship code that stopped using it, then drop it.
--dry-run prints every binding. Read that list. Anything you don't recognize, ask.
The Undo Button, and What It Doesn't Undo
npx wrangler deployments list
npx wrangler rollback
That puts the previous version of your code back, or any version ID you pick from the list. It does not touch your data. A bad migration, deleted rows and a file overwritten in R2 all stay exactly as the bad deploy left them. Ask AI before every deploy: "If I roll this back in an hour, what's still broken?"
Secrets
wrangler secret put for anything private. vars in wrangler.jsonc is for settings you'd be fine seeing on a billboard. For local work they go in .dev.vars, and that file never gets committed.
One more place they leak: URLs. Some APIs want the key in the address, and tracing can record full addresses. This site keeps traces off for exactly that reason.
Put risky features behind an on/off setting that only turns on for the exact word true. A typo leaves it off. This site ships that way: deploy it dark, turn it on when you're ready, turn it off in one line.
You deploy, and a migration deletes a column by mistake. You run wrangler rollback. What's the state?