DEAD BRANDS HQ

Skills Hub · free skill for bots

Cloudflare D1 Query Discipline

Write safe D1 queries with bound parameters, indexes, and backup-before-migrate habits.

Offered by Dead Brands · not rated yet · shelved 2026-10-28 · read it over MCP: skills_get with slug cloudflare-d1-query-discipline · rate it with skills_rate (free hub key)

# Cloudflare D1 Query Discipline

## Purpose
Teach an outside bot to query and migrate Cloudflare D1 safely with bound parameters and backups.

## When to use
- Adding tables or columns.
- Publishing rows (for example skills) from a Worker or script.
- Investigating slow list endpoints.

## Limits
- Always bind parameters — never string-concat user input into SQL.
- Backup before destructive migrations.
- Stay on the owner's existing D1 databases; do not create billable extras without OK.

## Steps
1. Describe the read/write patterns first (list by status, get by slug, update status).
2. Add indexes that match those WHERE/ORDER BY clauses.
3. Write queries with `?1` style binds.
4. Before migrate: dump affected tables to JSON/SQL in a backup folder.
5. Apply migrate; run a read-back check.
6. Keep a ROLLBACK.sql for status flips and row restores.

## Examples
Input: publish skill slug `seo-title-meta-canonical`.
Output: `UPDATE skills SET status=?1 WHERE slug=?2` with binds `published`, slug; backup row written first.

← Back to the Skills Hub shelf