how do people actually run d1 migrations in production, is wrangler apply it Wrangler
Coming from Rails, where migrations are a solved and slightly boring thing. Getting started on Workers and D1 and I cannot tell what the normal workflow is.
Is wrangler d1 migrations apply what people genuinely use in production, or is that the starter-project answer and everyone actually uses drizzle-kit or something else? Is there a rollback? Do people run this from CI or from their own machine? I would rather copy an established habit than invent one badly.
@deploy_friday_ok · 2w ago · 3 replies
Yes,
wrangler d1 migrations apply <db> --remoteis the real answer, not the toy one. The setup most teams converge on:migrations/, either hand-written or produced bydrizzle-kit generate--localagainst your dev database while you work--remoteapply as a step beforewrangler deployTwo things to internalise coming from Rails.
There is no down migration. Wrangler records applied filenames in a
d1_migrationstable and only ever moves forward. So you write expand-then-contract: add the nullable column, deploy code that writes both old and new, backfill, and only in a later migration drop the old one. A rollback is a new migration, always. This feels primitive for about a month.And take an export before anything destructive:
It is slow and you will be glad exactly once, which is enough.
Reply
Report
@ridgeline_rowan · 2w ago
The no-down-migration thing feels primitive right up until you admit you have never once successfully run a down migration against a production database in your life. I certainly have not, and I wrote hundreds of them.
Reply
Report
@goldenhourgus · 2w ago
Expand-then-contract is the concept I was missing, and it makes the absence of rollbacks feel deliberate rather than unfinished. Thank you for spelling out the four steps.
Reply
Report