Drizzle ORM for Postgres
Writes, reviews and debugs Drizzle ORM code for Postgres to match your version, so queries and migrations work.
What we improved
Brought the essential rules into SKILL.md (schema, queries, relations for both versions, migrations, types, errors, drivers) so it works on its own; before, everything after version detection was an index of reference files. Updated version
Improved by YourAISkill from the original by ptonlix, under its MIT licence. The download includes the author's licence and a CHANGES.md listing every change. Both Claude reviews read the improved version.
Claude's review
8/10 Version-aware Drizzle Postgres guide that separates v1 RC and 0.45.x APIs, with sharp rules on counts, errors, drivers and poolers plus deep reference files.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
Use this skill whenever the user is working with Drizzle ORM on PostgreSQL. This covers any mention of Drizzle, drizzle-orm, drizzle-kit, drizzle-zod, `pgTable`, `defineRelations`, `relations()`, `db.select()`, `db.query`, or insert/update/delete against Postgres. Typical intents to trigger on: - Designing or debugging Postgres table schemas, columns, identity PKs, enums, JSONB, arrays - Modeling one-to-many or many-to-many relations and join tables in Drizzle - Writing, optimizing, or preparing Drizzle queries (placeholders, `.prepare()`) - Generating Zod validators from Drizzle tables - Setting up TypeScript + Postgres projects (Neon, Supabase, postgres.js, node-postgres) with Drizzle - Migrating from Prisma, TypeORM, or Sequelize **to Drizzle** - Resolving Drizzle type errors; choosing between v1 RC and 0.45.x APIs Do NOT trigger for Drizzle with MySQL/SQLite, raw SQL without an ORM, or other ORMs when Drizzle is not the target.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: drizzle-best-practices
description: "Write, review and debug Drizzle ORM code for PostgreSQL that matches the installed Drizzle version: v1 release candidates (defineRelations, object-syntax relational queries, validators from drizzle-orm/zod) or the 0.45.x line (relations(), callback queries, drizzle-zod). Covers schema design (identity keys, timestamps, JSONB, enums, indexes, foreign keys), select, insert, update, delete and upsert, relations and many-to-many, drizzle-kit migrations, type inference and Zod validators, error handling (DrizzleQueryError and Postgres error codes), prepared statements and batching, and node-postgres, postgres.js, Neon, Supabase and serverless setup. Use whenever the user mentions Drizzle, drizzle-orm, drizzle-kit, drizzle-zod, pgTable, defineRelations or db.query against Postgres, or migrates from Prisma, TypeORM or Sequelize to Drizzle. Not for Drizzle on MySQL or SQLite, or other ORMs."
license: MIT
compatibility: TypeScript projects using Node.js or edge runtimes with drizzle-orm and a PostgreSQL database.
metadata:
author: Marc A. Maceira Zayas
abstract: >
Drizzle ORM best practices for TypeScript developers on PostgreSQL: version detection
between the v1 release candidates and 0.45.x, the core rules in SKILL.md, and 21 reference
files with incorrect and correct examples across schema, queries, relations, migrations,
types, performance, drivers and advanced patterns.
---
<!-- Modified by YourAISkill (youraiskill.com) on 2 December 2026 from the original by ptonlix. See CHANGES.md. -->
# Drizzle ORM Best Practices (PostgreSQL)
Work in this order: detect the version, apply the core rules below, and open a reference file when the task needs depth (index at the end).
## 1. Detect the version first
Drizzle is mid-transition to **v1**. The relations and relational-query APIs differ between the two lines, and v1 release candidates still change between RCs. **Read the project's `package.json` (and the installed version in `node_modules/drizzle-orm/package.json`) before writing code.**
| Installed `drizzle-orm` | Relations and `db.query` | Validators | Install |
|---|---|---|---|
| `1.0.0-rc.x` or `1.0.0-beta.x` | `defineRelations`, passed as `drizzle({ ..., relations })`; object-syntax `where` and `orderBy` | `drizzle-orm/zod` (also `/valibot`, `/typebox`, `/arktype`) | `npm i drizzle-orm@rc` and `npm i -D drizzle-kit@rc` |
| `0.4x` (0.45.x at the time of writing) | `relations()` helpers, passed with the schema as `drizzle({ ..., schema })`; callback or operator `where`, array `orderBy` | separate `drizzle-zod` package (and `drizzle-valibot` and so on) | `npm i drizzle-orm` and `npm i -D drizzle-kit` |
Check the current tags with `npm view drizzle-orm dist-tags`. On 2 December 2026 `latest` was 0.45.4 and `rc` was 1.0.0-rc.6, so **`npm i drizzle-orm` does not install v1**: a new project that wants the v1 API must ask for `@rc` explicitly, and drizzle-kit must come from the same line.
Rules that routinely trip up agents:
- **The SQL-like builder is the same in both lines.** `db.select().from(t).where(eq(t.id, 1))`, `db.insert()`, `db.update()`, `db.delete()` and the operator imports (`eq`, `and`, `gt` from `drizzle-orm`) work identically. Never rewrite builder filters into relational object syntax.
- **On v1, `db.query` is driven only by `defineRelations`.** Legacy `relations()` helpers still import from `drizzle-orm/_relations` so old files compile during a port, but they do not populate `db.query`, and recent RCs no longer accept a `schema` option in `drizzle()` at all. There is no `db._query` in current RCs.
- **Match the codebase.** Use what `package.json` says. If you see `relations()` and callback-style `db.query`, stay legacy. Only start a new project on v1 when the user wants the newest API and accepts a release candidate.
- **When an RC API does not compile, trust the installed types** (`node_modules/drizzle-orm/**/*.d.ts`) over memory or older docs.
## 2. Core rules
### Schema
...From ptonlix's repository, MIT licence.
Related skills
-
Checked
Safe Postgres migrations
Plans Postgres schema changes with the right locks and backfills, so migrations run without downtime.
9/101 credit -
Checked
Reversible database migrations
Writes safe, reversible migrations for Postgres, Prisma, Django and others, so tables change without downtime.
8/101 credit -
Checked
MySQL and MariaDB tuning
Guides MySQL and MariaDB schema, indexes, EXPLAIN plans and replication, so your database runs smoothly.
7/101 credit -
Checked
Prisma schema and queries
Writes Prisma schemas, queries and migrations to current Prisma 7 rules, so your code avoids old habits.
7/101 credit -
Checked
BigQuery migration checks
Validates that tables moved to BigQuery match their source on schema, aggregates and rows, so nothing is lost.
7/101 credit -
Checked
Query driven schema design
Designs tables, keys and indexes from your real query patterns, so your data model stays fast as it grows.
7/101 credit