Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Drizzle D1 Workflow: Local Migrations That Match Prod

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โ€ฆ

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.

The 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.

To 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.

The 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.

The 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.

Rewritten by urgent.news; may contain errors โ€” check the original.

Source: dev.to

Read the original at dev.to โ†’

Report a problem with this story

More in Tech

Same product, two bios. Which one belongs on the project page?

โ€œI'm building PasteCharm, a tool for making profile bios.โ€ That line makes sense under my name. Move it to the PasteCharm project page and it sounds like I forgot whose profile I was editing.

  • "PasteCharm" is a tool for editing profile bios
  • Project page headline should read "PasteCharm - A tool for making profile bios"
  • Intro paragraph should highlight key actions: pick a template, edit, copy

Canvas toBlob Explained: Exporting Images Without a Server Round-Trip

Canvas toBlob Explained: Exporting Images Without a Server Round-Trip In browser image processing, the moment that decides whether your tool is private or not is the export.

  • "canvas.toBlob()" converts canvas image to Blob without server
  • Quality parameter affects only lossy formats like JPEG/WebP
  • Developers must consider memory usage and browser support

11,932 WordPress plugin vulnerabilities in 12 months. One in six has no fix

โ€œKeep your plugins updatedโ€ is the advice every WordPress site owner has heard. We counted what that advice actually covers, and what it does not.

  • 11,932 WordPress plugin vulnerabilities documented in 12 months
  • One in six vulnerabilities lack a fix, 2,026 plugins vulnerable
  • 44% of vulnerabilities exploitable without any account

More from Tuesday 24 November โ†’