Auth & Data
Evolve a live Drizzle schema without data loss: prefer additive changes, reach for a surgical hand-written ALTER over db:push, and treat the journal as the source of truth.
1 file
Description
Evolve a live Drizzle schema without data loss: prefer additive changes, reach for a surgical hand-written ALTER over db:push, and treat the journal as the source of truth.
Adding a column, table, or index to a schema that a live app already writes to, or resolving drift between db/schema.ts and the deployed database.
drizzle-kit push diffs the schema and applies the change directly, skipping the migration history. When it sees a rename it can read the diff as a drop-plus-add and silently destroy a column. Use push only against a throwaway local database. Anywhere that holds data you cannot lose, use generate (writes a numbered SQL file plus a journal entry) then migrate.
The safe change is one that only adds:
generate sometimes proposes a drop-and-recreate for what is really a rename or a type widen. Do not apply that. Replace it with a surgical statement that preserves data:
-- instead of DROP COLUMN old / ADD COLUMN new:
ALTER TABLE "credit_balances" RENAME COLUMN "is_admin" TO "is_owner";
-- add a column without rewriting the table:
ALTER TABLE "request_traces" ADD COLUMN "kind" text DEFAULT 'other' NOT NULL;
Keep the hand-written file in the migrations folder and its entry in the journal so history stays linear.
The _journal.json and the numbered SQL files ARE the migration history. Read the generated SQL before applying it, commit it, and run migrate in the deploy step. Never edit an already-applied migration; add a new one. Migrations that take advisory locks want Neon's direct (non-pooled) connection string.
db:push against production can drop a column on any change it reads as a rename. Reserve it for disposable local databases.ALTER ... RENAME or additive ADD COLUMN.NOT NULL column with no default fails against a table that already has rows. Add a default or backfill first, then tighten.Related
Added 2026-07-01. Back to the Skill Library.

New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.