{
  "id": 21577836,
  "title": "Drizzle D1 Workflow: Local Migrations That Match Prod",
  "url": "https://urgent.news/2026/11/24/drizzle-d1-workflow-local-migrations-that-match-prod",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-24T10:21:47.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/saiful7778/drizzle-d1-workflow-local-migrations-that-match-prod-586l"
  },
  "original_language": "en",
  "account": "The article discusses the problem of resetting staging databases with fresh roles in a Drizzle D1 workflow that matches production. The author highlights that copying a seed command with a single variable omission leads to unintended consequences when the remote (production) database is cleared instead of the local staging database.\n\nThe author identifies three initial attempts at fixing the issue. The first involves flipping the remote flag to false, which inadvertently configures the binding for production instead of the intended local development environment. The second approach is to run drizzle-kit migrate with the HTTP config for each target, but this bypasses D1's migration ledger and causes two tools to claim ownership of the applied-version list. The third strategy is to check the ENVIRONMENT variable inside the seed, but this fails as the value resides in the Worker binding, not in the Node process launching the seed.\n\nTo address these issues, the author proposes making the target explicit and implementing a \"fail closed\" approach. The code is modified to check if SEED_REMOTE is true and if the target is not defined; if so, an error is thrown. This ensures that a SEED_ENV is required for remote seeds.\n\nThe author also draws an analogy to air traffic control, emphasizing that migration files act as numbered flight plans, and migrations_dir is the plan number on file. The wrangler d1 migrations apply command grants clearance, while drizzle-kit generate writes plans. The DB binding represents the runway where requests land. The author notes that a plan filed for the wrong runway ends up at the wrong airport, and a binding called DB provides no insight into which database is behind it.\n\nThe author concludes by outlining the steps to use this fix. The schema folder, generators, column helpers, and seed are set up similarly to a plain SQLite setup described in Drizzle SQLite Setup: One Schema, No Drift. The only changes are in the client, one config file, and the apply path. The install command includes adding drizzle-orm, drizzle-kit, wrangler, @libsql/client, and dotenv. The file tree includes src/db/clients/drizzle-client.ts, src/db/schemas/index.ts, src/db/seed/seed-db.client.ts, and wrangler.jsonc.",
  "summary": "The same SQLite schema, three apply paths, and a seed command that silently picks production when you forget one variable. The Problem You want to reset staging with fresh roles. You copy a seed command, omit one variable, and run it: SEED_REMOTE = true WRANGLER_CONFIG_PATH = \"wrangler.seed.jsonc\" \\ tsx ./src/db/seed/dev-seed/index.ts 🌱 Starting database seed... 🔌 Connecting to the REMOTE…",
  "key_points": [
    "Drizzle D1 workflow aims to match production migrations for local staging databases.",
    "Three initial attempts to fix the issue fail due to misconfiguration and ownership conflicts.",
    "Proposed solution checks SEEDREMOTE and target, requiring SEEDENV for remote seeds."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}