Create, inspect, apply, baseline, import, or recover Cloudflare D1 schema migrations across local, preview, and remote databases. Use when Wrangler D1 migration state or schema drift is the main risk.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cloudflare-d1-migrations:cloudflare-d1-migrationsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- The repository uses Cloudflare D1 and the task changes schema, indexes, constraints, or migration files.
migrations_dir, migrations_table, or preview/remote database settings and those settings matter to the workflow.database-migrations for the general migration workflow instead.preview_database_id, or Wrangler env setup drift with no migration file, import baseline, or schema-state concern; use configuration-env.cloudflare-d1-query-tuning.Required before editing
d1_databases binding involved.database_name, binding name, preview_database_id, and any custom migrations_dir or migrations_table.package.json scripts, Makefile targets, CI commands) and whether they already wrap Wrangler.--local, --preview, or --remote.Helpful if present
wrangler dev or wrangler d1 ... --local --persist-to.wrangler dev, or build steps.Only investigate if encountered
d1_migrations.First confirm the request is actually about migration or schema state, not just a missing binding, env value, or runtime query bug. If schema and migration files are unchanged, say explicitly that this is not a migration or schema-state task and redirect before you inspect the D1 migration ledger. Otherwise inspect the Wrangler config and repo wrappers before suggesting commands so you identify the exact D1 binding, preview/remote targets, migration directory/table, and local persistence path without mixing local, preview, and remote state.
Confirm the D1 migration contract and environment mapping.
wrangler.toml, wrangler.json, or wrangler.jsonc and note the chosen d1_databases entry.database_name, binding name, preview_database_id, and any custom migrations_dir or migrations_table; do not assume defaults if config says otherwise.wrangler d1 migrations create, list, and apply.Create the migration the D1 way.
npx wrangler d1 migrations create <DB> <message>.PRAGMA defer_foreign_keys = true at the right point in the SQL.down sections.Validate locally before promotion.
npx wrangler d1 migrations list <DB> --local.--persist-to <dir> in both list and apply commands.npx wrangler d1 migrations apply <DB> --local.npx wrangler d1 execute <DB> --local --command "<sql>" and then run the repo's tests or wrangler dev path.Promote in environment order, not by assumption.
preview_database_id is configured. If it is, inspect and apply there with --preview before touching remote; if it is not, say that plainly and move from local validation to remote.npx wrangler d1 migrations list <DB> --preview or --remote.npx wrangler d1 migrations apply <DB> --remote.Recover drift or import existing SQL safely.
d1_migrations or the configured migrations_table) and current schema before changing anything.BEGIN TRANSACTION / COMMIT, remove any CREATE TABLE _cf_KV ... definition, split oversized inserts if D1 reports Statement too long, and watch foreign-key ordering or virtual-table issues.npx wrangler d1 execute <DB> --local|--remote --file=<dump.sql> or the repo wrapper that maps to it for the actual import path.migrations_dir / migrations_table before suggesting file paths or ledger queries.down migrations for D1; use corrective forward migrations or explicit D1 recovery tooling.--preview when config or repo workflow actually uses a preview database.wrangler d1 execute inspection rather than only trusting console success text.wrangler d1 migrations list shows the expected pending or clean state in the targeted environments.wrangler d1 execute or equivalent repo wrappers after applying.wrangler dev, or build/deploy validation.references/contract-and-promotion.md when the main risk is choosing the right D1 binding, migration directory/table, persistence path, or preview/remote promotion order.references/recovery-and-imports.md when the task involves remote drift, D1 recovery, SQLite import/export, or dump cleanup.references/boundaries-and-false-positives.md when the request mentions D1 but may actually be binding/config drift, runtime query behavior, or a repo with no preview database.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub matt-riley/lucky-hat --plugin cloudflare-d1-migrations