{
  "slug": "wrangler-d1-migrations-pattern-selects-migration-files-27bcd6116dd5",
  "title": "wrangler D1 migrations_pattern selects migration files",
  "tools": [
    "wrangler"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-06-05T10:47:44.000Z",
  "announced_at": "2026-06-05T10:47:44.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When D1 migrations use nested directories, set `migrations_pattern` in the binding and run `wrangler d1 migrations apply` or `wrangler d1 migrations list` for the database. The pattern must start with the configured `migrations_dir`; `migrations_pattern` is optional and defaults to `${migrations_dir}/*.sql`.",
    "examples": [
      "{\n  \"d1_databases\": [{\n    \"binding\": \"DB\",\n    \"database_name\": \"<DATABASE_NAME>\",\n    \"database_id\": \"<UUID>\",\n    \"migrations_dir\": \"migrations\",\n    \"migrations_pattern\": \"migrations/*/migration.sql\"\n  }]\n}",
      "npx wrangler d1 migrations apply <DATABASE>",
      "npx wrangler d1 migrations list <DATABASE>"
    ],
    "gotchas": [
      "Version: 4.98.0",
      "migrations_pattern: Glob for discovering migrations, relative to the Wrangler config file. `*` matches one path segment; `**` matches any number. Must start with `migrations_dir`.",
      "migrations_dir (required): Required when `migrations_pattern` is set; pattern must start with this directory.",
      "<DATABASE> (required): Database name or binding for the migration command.",
      "Prerequisite: Set `migrations_dir` when configuring `migrations_pattern`.",
      "Prerequisite: For a nested-only pattern, Wrangler's `migrations create` writes top-level files; generate new migrations using the ORM's command, such as `drizzle-kit generate`.",
      "`migrations_pattern` is a glob relative to the Wrangler config file.",
      "Files that do not match the pattern are not executed.",
      "The default pattern is `${migrations_dir}/*.sql`, preserving today's behaviour.",
      "When no migrations match the configured pattern but files matching `migrations/*/migration.sql` exist, Wrangler logs a hint suggesting `migrations_pattern` as an opt-in."
    ]
  },
  "why_it_matters": "Apply and list D1 migrations stored in nested layouts such as ORM-generated migration folders.",
  "sources": [
    "https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.98.0",
    "https://developers.cloudflare.com/d1/reference/migrations/",
    "https://developers.cloudflare.com/d1/wrangler-commands/"
  ],
  "rank": 0.97041,
  "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-40c1f70e01209979-0:gate",
    "evidence_hash": "516917ad6f4f82b126c35837f5002cbba2d9ac7c5f90642053004e904bcbbecf"
  },
  "review": {
    "draft_hash": "b5ce1bf51ace6e3986a8fe4971c337427f4b150b5c9aba9cccae8a42c024f1fa",
    "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.81 (>= 0.6 needed)."
  }
}
