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.
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--forceto 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.
pushoutput in a CI log contains lines such asYou're about to delete ... column in orders table with N itemsor 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
migratefails on the first run: the initial generated migration tries toCREATE TABLE "orders"and errors withrelation "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 |
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.
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.