Illustration of a TypeScript schema file turning into a numbered SQL migration that is applied to a Postgres database
Illustration by AIUseFlow · credits

Drizzle ORM Tutorial: Change Your Postgres Schema Safely With generate, migrate and push

Also available in Hindi: यह लेख हिंदी में पढ़ें

Drizzle ORM lets you describe Postgres tables in TypeScript, and its CLI, drizzle-kit, turns changes to that file into database changes. The part that confuses most people is choosing between push and generate + migrate. This guide sets up a small project and shows when to use each.

Step 1: Install the packages

The official Postgres guide installs drizzle-orm, pg and dotenv, plus drizzle-kit, tsx and @types/pg as dev dependencies. Note that the docs currently add the @rc tag (the 1.0 release candidate); on 19 Nov 2026 npm's stable latest was drizzle-orm 0.45.4 and drizzle-kit 0.31.11. Pick one line and keep both packages on it.

Put your connection string in .env as DATABASE_URL.

Step 2: Write the schema and config

In src/db/schema.ts, declare a table with pgTable, for example a users table with an identity id, a name and a unique email. Then create drizzle.config.ts in the project root with defineConfig, setting out: './drizzle', your schema path, dialect: 'postgresql' and dbCredentials.url.

Step 3: Prototype fast with push

Drizzle generate and migrate flow from TypeScript schema to applied SQL
From Drizzle's migrations, generate and migrate docs. Illustration, not a screenshot.
npx drizzle-kit push

push reads your schema, introspects the database, works out the difference and applies it directly. No SQL files are written. Add --explain to print the planned SQL without applying it, and --verbose to see every statement. Avoid --force unless you mean it: it auto-accepts statements that can lose data.

Step 4: Use generate and migrate for production

npx drizzle-kit generate --name=init
npx drizzle-kit migrate

generate compares your schema with the previous snapshot, asks you about renames when it is unsure, and writes an SQL migration you can review and commit. migrate reads the migrations folder, checks which ones are already recorded in the __drizzle_migrations table (in the drizzle schema by default), and applies only the new ones. You can also run them at app start with migrate() from drizzle-orm/node-postgres/migrator.

Step 5: Avoid the common traps

Comparison table of drizzle-kit push, generate plus migrate, pull and runtime migrate
From Drizzle's migrations docs and Neon's Drizzle guide. Illustration, not a screenshot.

Related reading: the best database for side projects, Neon read-only roles for AI agents, fixing Supabase CLI v3 in CI and the Drizzle ORM tool page.

Sources

FAQ

Should I use drizzle-kit push or migrate?

Use push for quick local prototyping. Use generate plus migrate when you want SQL files you can review and commit.

Where does Drizzle record applied migrations?

In a __drizzle_migrations table in the drizzle schema by default; both names can be changed in the config.

Can I preview what push will change?

Yes. Run drizzle-kit push --explain to print the planned SQL without applying it.

Can Drizzle read an existing database?

Yes. drizzle-kit pull introspects the database and writes a TypeScript schema file.

About the author

Suraj Kumar builds and edits AIUseFlow, a directory of AI tools for vibe coders, agent builders and creators. Guides like this one walk through a practical workflow with cited sources — not a news wire rewrite. How we rank tools.

Get the weekly stack

Rank movers and new AI tools for builders, once a week. Free, no spam, unsubscribe anytime.