Drizzle push vs migrate in Production

The project started with drizzle-kit push because it was fast: edit schema.ts, run one command, and the database matches. Months later the same command is in the production deploy script, and a column rename in the TypeScript schema has just been applied as a drop and an add — push asked for confirmation in the terminal, but in CI the prompt was bypassed with --force, and a column of customer data is gone. Drizzle offers two workflows that look equivalent on a laptop and behave very differently in production: push diffs the schema against the live database and applies the result immediately, while generate plus migrate produces reviewed SQL files that a migrator applies in order. This guide explains the difference, why production needs the second, and how to move a database that has only ever been pushed onto versioned migrations without disruption. It belongs to Drizzle ORM Type Sync.

Two Drizzle Workflows Two panels. push: introspects the live database, diffs against schema.ts, applies statements immediately, no files, no history, prompts on data loss. generate plus migrate: diffs schema.ts against the last snapshot, writes a SQL file for review, the migrator applies it in order and records it in __drizzle_migrations. Two Drizzle Workflows drizzle-kit push introspect live DB, diff, apply now no SQL file, no review surface data-loss prompts (bypassed with --force) no record of what ran prototyping only generate + migrate diff against snapshot → SQL file reviewed and edited in a PR migrator applies in journal order __drizzle_migrations records it production
push has no artefact to review and no history to audit; generate + migrate has both, which is what production needs.

Symptom / Error Signatures

Signs that push is being used where it should not be:

  • The deploy script or CI job runs drizzle-kit push, often with --force to skip interactive prompts.
  • There is no migrations folder, or it exists but is stale, and nobody can say which statements ran against production last week.
  • push output in a CI log contains lines such as You're about to delete ... column in orders table with N items or a rename question that was answered automatically.
  • Staging and production drift apart, because each was pushed from a different branch at a different time.
  • Switching to migrate fails on the first run: the initial generated migration tries to CREATE TABLE "orders" and errors with relation "orders" already exists.

Root Cause Analysis

push is a declarative apply: it introspects the database, computes the statements needed to match schema.ts, and runs them. That is excellent for local iteration and throwaway databases. In production it has the weaknesses of every unreviewed declarative apply, described in Declarative Schema Management: renames become drop-plus-add unless a human answers the prompt correctly, blocking DDL is emitted in its plain form, nothing records what ran, and the plan is computed at apply time rather than reviewed beforehand.

generate + migrate is a versioned workflow. generate compares schema.ts with the last snapshot — not with the live database — and writes a SQL file that can be read, edited for online DDL, and reviewed. The migrator applies files in journal order inside a transaction and records each one, so every environment runs the same statements in the same order.

Property push generate + migrate
Compares against live database last snapshot
Reviewable artefact none SQL file per change
History none __drizzle_migrations
Rename handling interactive prompt edit the generated SQL
Online DDL not controllable edit or custom migration
Same statements in every environment no yes
Moving a Pushed Database onto Migrations Five steps. Generate an initial migration from schema.ts; confirm it matches production with a diff; mark it as applied in production without running it by inserting its hash into __drizzle_migrations; switch the deploy to migrate; from now on every change is generated, reviewed and migrated. Moving a Pushed Database onto Migrations STEP 1 Generate baseline 0000_baseline.sql STEP 2 Prove it matches scratch DB vs prod diff STEP 3 Record as applied insert into __drizzle_migrations STEP 4 Deploy uses migrate remove push STEP 5 Normal workflow generate → review → migrate
The baseline migration is recorded as applied on the existing database, so the migrator starts from the current state instead of recreating it.

Immediate Mitigation

1. Remove push from every non-development pipeline today. Until migrations are in place, apply changes by generating SQL and running it after review rather than pushing.

2. Generate a baseline migration from the current schema. With an empty migrations folder, the first generate produces the full schema as one migration.

# Shell · project root · no database connection needed for generate
npx drizzle-kit generate --name=baseline
# drizzle/0000_baseline.sql + meta/_journal.json + meta/0000_snapshot.json

3. Prove the baseline matches production. Apply it to a scratch database and compare schemas, the same parity check used in baselining an existing production database.

# Shell · scratch database only · compares structure, not data
psql "$SCRATCH_URL" -v ON_ERROR_STOP=1 -f drizzle/0000_baseline.sql
diff <(pg_dump --schema-only --no-owner "$SCRATCH_URL" | grep -v '^--') \
     <(pg_dump --schema-only --no-owner "$PROD_READONLY_URL" | grep -v '^--') && echo parity OK

4. Record the baseline as applied on production. The PostgreSQL migrator tracks migrations in drizzle.__drizzle_migrations with a hash of the SQL file and a timestamp. Run the migrator once against a scratch database to see the exact row it writes for the baseline, then insert that row into production so the migrator skips it.

-- PostgreSQL · production · migration role · run once, after the parity check
-- WARNING: copy hash and created_at from the row the migrator wrote on the scratch database.
CREATE SCHEMA IF NOT EXISTS drizzle;
CREATE TABLE IF NOT EXISTS drizzle.__drizzle_migrations (id SERIAL PRIMARY KEY, hash text NOT NULL, created_at bigint);
INSERT INTO drizzle.__drizzle_migrations (hash, created_at)
VALUES ('<hash from scratch run>', <created_at from scratch run>);
-- ROLLBACK PATH: DELETE FROM drizzle.__drizzle_migrations WHERE hash = '<hash>';

Permanent Fix / Long-Term Pattern

Use push only against local and ephemeral databases, and generate + migrate everywhere else. The production flow is: change schema.ts, run generate, read the SQL, edit it for zero-downtime concerns (renames, online indexes, NOT VALID constraints), add custom migrations for data and supporting objects as described in generating custom SQL migrations in Drizzle Kit, and let the pipeline run the migrator once before the application rolls out.

// TypeScript · scripts/migrate.ts · run once per deploy by the pipeline, not at app startup
// WARNING: uses a dedicated migration connection with DDL privileges and a lock timeout.
import { drizzle } from "drizzle-orm/node-postgres";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import { Pool } from "pg";

const pool = new Pool({ connectionString: process.env.MIGRATION_URL, options: "-c lock_timeout=3000" });
await migrate(drizzle(pool), { migrationsFolder: "./drizzle" });
await pool.end();
// ROLLBACK PATH: forward-fix with a new migration; Drizzle has no automatic down migrations.

Guard the boundary in CI: fail if any pipeline file invokes drizzle-kit push, and fail if drizzle-kit generate produces a new file on a clean checkout, which would mean someone changed schema.ts without committing the migration. Drift between environments that were pushed in the past is best caught with a scheduled comparison, as in resolving Drizzle schema drift detection errors.

Which Command Where Matrix of environments against the Drizzle command to use. Local development uses push for speed. Preview or ephemeral databases may use push. CI uses generate with a no-new-file check and migrate against a test database. Staging and production use migrate only. Which Command Where Environment Command Why local development push fast iteration, disposable data ephemeral preview DB push or migrate rebuilt per branch CI generate check + migrate prove files match schema.ts staging migrate only same statements as production production migrate only reviewed, recorded, ordered
push stops at the edge of anything shared; everything shared is migrated from reviewed files.

Verification Checklist

Frequently Asked Questions

Is drizzle-kit push ever acceptable in production? Not for databases that serve users. It applies an unreviewed plan computed at run time, leaves no history, and relies on interactive prompts for rename and data-loss decisions. Keep it for local and throwaway databases.

Why does the first migrate on a pushed database fail? Because the first generated migration creates every table, and those tables already exist. Baseline instead: prove the generated SQL matches production, then record that migration as applied so the migrator starts after it.

Does generate look at the database? No. It compares schema.ts with the latest snapshot in the migrations folder. That is why it is deterministic and reviewable — and why drift in the database is invisible to it unless you check separately.

Does Drizzle support down migrations? Drizzle Kit does not generate down migrations. Roll back by deploying a forward migration that reverses the change, and keep changes backward compatible so that rolling back the application does not require touching the schema.