{
  "slug": "createtestharness-worker-handles-apply-local-d1-migrations-6fb2d71b8e9c",
  "title": "createTestHarness() Worker handles apply local D1 migrations",
  "tools": [
    "wrangler"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-06-30T16:38:09.000Z",
  "announced_at": "2026-06-30T16:38:09.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When tests need a local D1 schema before requests, call `applyD1Migrations(\"DATABASE\")` on the Worker handle returned by `server.getWorker()`; call it after storage is reset.",
    "examples": [
      "const worker = server.getWorker();\nbeforeEach(async () => {\n  await worker.applyD1Migrations(\"DATABASE\");\n});"
    ],
    "gotchas": [
      "Version: wrangler@4.106.0",
      "bindingName (required): D1 binding to migrate; reads its Wrangler migration settings.",
      "Prerequisite: Use a test harness Worker with a configured D1 binding. Migrations use configured `migrations_dir` and `migrations_pattern`; without them, `.sql` files are read from the `migrations` directory relative to the config file.",
      "Applies local D1 migrations before running requests."
    ]
  },
  "why_it_matters": "Run tests that need a local D1 database schema initialized before sending requests to a test harness Worker.",
  "sources": [
    "https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.106.0",
    "https://developers.cloudflare.com/workers/testing/test-harness/prepare-test-state/",
    "https://developers.cloudflare.com/workers/wrangler/api/"
  ],
  "rank": 0.97027,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v1+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "backfill-20261007",
    "verdict_id": "backfill-20261007:backfill-20261007-2841bfddc8d257e6-4:gate",
    "evidence_hash": "630dc99354ee14d0aca270af3150e2f48682af60af86551fa937bfdb7badd326"
  },
  "review": {
    "draft_hash": "3e33f852027c7b5f9d395440ab0b262147e3087dfed2e2f175b133d9a254930e",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "backfill-20261007:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.97 >= 0.9; 2 needed) and Jev gave 0.76 (>= 0.6 needed)."
  }
}
