Auth & Data
Neon + Drizzle Migrations
Use when defining or changing a database schema with Drizzle ORM on Neon Postgres, generating a migration, or applying one to a live database. Also use when the schema file and the deployed database have drifted, a migration fails to apply, or local and production disagree about a column. If a table definition changes, use this skill.
1 file
Description
Use when defining or changing a database schema with Drizzle ORM on Neon Postgres, generating a migration, or applying one to a live database. Also use when the schema file and the deployed database have drifted, a migration fails to apply, or local and production disagree about a column. If a table definition changes, use this skill.
name: neon-drizzle-migrations description: Use when defining or changing a database schema with Drizzle ORM on Neon Postgres, generating migrations, or debugging a drift between the schema file and the live database.
Neon + Drizzle Migrations
When to trigger
Adding or altering a table, wiring the first DB connection, or resolving a migration that will not apply.
Steps
-
Define the schema in
db/schema.ts:import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: text("id").primaryKey(), email: text("email").notNull().unique(), isOwner: boolean("is_owner").default(false).notNull(), createdAt: timestamp("created_at").defaultNow().notNull(), }); -
Point
drizzle.config.tsat the schema and setDATABASE_URLto the Neon pooled connection string. -
Generate SQL from the schema diff:
pnpm drizzle-kit generate. Read the generated file indrizzle/before applying it. -
Apply it:
pnpm drizzle-kit migrate. -
Inspect data with
pnpm drizzle-kit studio.
Local vs production
- Keep
DATABASE_URLin.env.localfor dev and in the host env for production. Never hardcode it. - Run
generatelocally and commit the SQL. Runmigratein a deploy step or manually against production. Do notpushto production -pushskips the migration history and can drop columns.
Pitfalls
drizzle-kit pushis for fast local iteration only. It diffs and applies directly, which can silently drop a column when you rename one. Usegenerate+migrateanywhere that holds real data.- Neon has a pooled and a direct connection string. Migrations that use advisory locks want the direct (non-pooled) URL. App queries use the pooled URL.
- The app should build even without
DATABASE_URL. Guard the client creation so a missing env var does not fail the whole build.
Added 2026-07-01. Back to the Skill Library.

Get Smarter About AI Dev
New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.