Skip to content

Why drizzle-kit push is banned before deploy

Push-mode migration is refused on any project that has a migration journal, and it hung a Railway deployment when it ran as a pre-deploy hook.

This deployment once had kywi migrate --push wired as its platform pre-deploy command. drizzle-kit push compares schema to database and asks before anything lossy — on that upgrade, whether to truncate a table to add a unique constraint. A pre-deploy container has no terminal to answer with, so the process did not fail: it waited, forever, and every later deploy queued behind it.

Deployment 71f49aa1 had to be cancelled through the platform's GraphQL deploymentCancel mutation, because the CLI at the time had no cancel command. The pre-deploy hook was then cleared — and the next railway redeploy hung the same way, because redeploy re-uses the previous deployment's frozen settings and ran the hook that no longer existed. 908b82f8 had to be cancelled too.

Core refuses the combination now

Once kywi-generated/migrations/meta/_journal.json exists, the project is journal-managed and --push exits 1 before spawning anything:

text
✖ Refusing to run 'drizzle-kit push': this project is journal-managed (a migration journal exists at <repo>/kywi-generated/migrations) — --push will apply changes the journal will not record, desyncing them. Subsequent journal-based migrations may then fail or silently skip that change.
  Re-run with '--push --force-push' to proceed anyway, or drop --push to use the journal-based migrate path instead.

The exit happens before drizzle-kit is spawned at all, so a refused run has changed nothing and is safe to see mid-deploy. Note what this does not cover: a project that has never adopted a journal is exactly the case --push is still allowed in, which is the case the incident above happened in. The refusal protects your schema history; the rule at the bottom of this page is what protects your deploys.

What desyncing means

push writes straight to the database and never touches meta/_journal.json. A later drizzle-kit generate therefore diffs against a journal that never recorded the pushed change, and the next migrate either skips that change silently or fails applying a migration the live database already has. Neither is discovered on the deploy that caused it.

The standing rule

No migration command in any deploy hook, on any platform. Migrate from an operator machine against the database's public proxy, verify, then release — Running migrations against a live database. And after changing a service's settings, trigger a fresh source deploy rather than redeploying the last one:

bash
# reads frozen settings from the previous deployment — including hooks you removed
railway redeploy

# builds from source with the service's CURRENT settings
git commit --allow-empty -m 'redeploy' && git push

The dashboard's Deploy button and the GraphQL serviceInstanceDeploy(serviceId, environmentId) mutation do the same thing as the second form.