drizzle-best-practices — Claude Code skill for Drizzle ORM on Postgres
A skill that steers your agent toward correct Drizzle ORM code on PostgreSQL: schemas, queries, relations, migrations. Useful on any TypeScript plus Postgres project.
npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a claude-codeWhat drizzle-best-practices does
The skill fires whenever Drizzle comes up in conversation — drizzle-orm, drizzle-kit, drizzle-zod, pgTable, db.select(), db.query, or insert/update/delete against Postgres. From there the agent works off reference files covering 8 categories, ordered by impact: schema design and query patterns first, advanced features last.
Before writing any code, the skill tells the agent to check package.json. Drizzle is mid-transition to v1, and the relations API differs between the two lines. On ^1.0.0-rc you get defineRelations, object-syntax relational queries, and validators from drizzle-orm/zod. On ^0.4x it is the legacy relations() helper plus the separate drizzle-zod package. Watch out: npm i drizzle-orm resolves to 0.45.2, not v1, so a new project has to ask for the @rc tag explicitly.
Postgres only. The skill stays out of the way for Drizzle with MySQL or SQLite, and for raw SQL without an ORM. One thing it warns against: the SQL-like builder is identical across versions, so db.select().from(t).where(...) should not be rewritten into relational object syntax — only the relational query layer changed. Engine-specific patterns like identity columns, JSONB, arrays and enums live in a dedicated file under references/.
What it helps with
- design Postgres tables with
pgTablewithout common mistakes - model one-to-many and many-to-many relations in Drizzle
- pick the right relations API for the installed drizzle-orm version
- generate Zod validators straight from table definitions
- port a project from Prisma, TypeORM or Sequelize to Drizzle
Example prompts for the agent
- Design the schema for a blog on Drizzle: users, posts, tags. Check the drizzle-orm version in package.json before writing code.
- Why doesn't db.query see my relations? I'm on drizzle-orm 1.0.0-rc.3.
- Convert these relations() calls to defineRelations and show what changes in the queries.
How to install drizzle-best-practices
1Skills CLI (Vercel)
npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a claude-code2Manually: put the files in place
~/.claude/skills/drizzle-best-practices/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/drizzle-best-practices/
1Skills CLI (Vercel)
npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a codex2Manually: put the files in place
.agents/skills/drizzle-best-practices/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a cursor2Manually: put the files in place
.cursor/skills/drizzle-best-practices/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install honra-io/drizzle-best-practices drizzle-best-practices2Manually: put the files in place
.github/skills/drizzle-best-practices/SKILL.md1Skills CLI (Vercel)
npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a gemini-cli2Platform CLI
gemini skills install https://github.com/honra-io/drizzle-best-practicesManually: put the files in place
.devin/skills/drizzle-best-practices/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about drizzle-best-practices
How do I install drizzle-best-practices in Claude?
Run npx skills add honra-io/drizzle-best-practices --skill drizzle-best-practices -a claude-code. The skill file lands at ~/.claude/skills/drizzle-best-practices/SKILL.md.
What does drizzle-best-practices do?
It gives the agent rules for Drizzle ORM on PostgreSQL — schemas, queries, relations, migrations, types, performance. It reads package.json to detect the API version and matches its advice to it.
Does it work with MySQL or SQLite?
No. It targets PostgreSQL and does not trigger for Drizzle with MySQL or SQLite, or for raw SQL without an ORM.
Source text
SKILL.md · MIT
---
name: drizzle-best-practices
description: |
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.
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: >
Comprehensive Drizzle ORM best practices guide for TypeScript developers building on
PostgreSQL. Contains guidance across 8 categories from critical (schema design, query
patterns) to incremental (advanced features). Each reference includes explanations,
correct vs incorrect code examples, and rationale for why the pattern matters.
Engine-specific Postgres patterns (identity columns, JSONB, arrays, enums, etc.) are
documented in a dedicated reference file to keep the skill modular.
---
# Drizzle ORM Best Practices (PostgreSQL)
Comprehensive best practices guide for Drizzle ORM with PostgreSQL. Contains guidance across
8 categories, prioritized by impact to help you write correct, performant, and maintainable
database code.
## Version & API Detection (read this first)
Drizzle is mid-transition to **v1**, and the relations + relational-query APIs differ between
the two major lines. **Check the project's `package.json` before writing code** so you emit the
right syntax:
| Installed `drizzle-orm` | API to use | Install command |
|---|---|---|
| `^1.0.0-rc` or `^1.0.0-beta` | **v1 — the default in this skill.** `defineRelations`, object-syntax relational queries (`where: { … }`, `orderBy: { … }`), validators from `drizzle-orm/zod` | `npm i drizzle-orm@rc` + `npm i -D drizzle-kit@rc` |
| `^0.4x` (e.g. `0.45.2`) | **Legacy.** `relations()` helper, callback/operator relational queries, validators from the separate `drizzle-zod` package | `npm i drizzle-orm` (resolves to 0.45.2) |
The current release candidate is **`[email protected]`** (the `@rc` tag), which supersedes the
older `@beta` tag the docs still reference in places.
Three things that routinely trip up agents:
- **`@latest` is still `0.45.2`, not v1.** `npm i drizzle-orm` does *not* get you v1 — a new project
that wants the v1 API must ask for `@rc` explicitly.
- **The SQL-like query builder is unchanged across versions.** `db.select().from(t).where(eq(t.id, 1))`,
`db.insert()`, `db.update()`, `db.delete()` work identically in 0.45.x and v1. Only the relational
query API (`db.query`) and relation *definitions* changed. Never rewrite `db.select()` operator
filters into the relational object syntax.
- **On v1, the relational query API (`db.query`) is driven by `defineRelations`.** Passing a
legacy `schema` does *not* populate `db.query`. The old `relations()` helper is still importable
from `drizzle-orm/_relations` so existing relation modules keep compiling during a port, but to
query relationally on v1 you convert them to `defineRelations`. (Earlier betas exposed a
`db._query` path; it was removed before `1.0.0-rc.3`.) See `references/relations-defining.md`.
When the version is unstated, default to **v1 (RC)** for new code, but match the existing codebase's
API if you already see legacy `relations()` / callback-style `db.query` patterns in use. Throughout
the reference files, version-specific differences are marked with **"Legacy (v0.45.x)"** callouts.
## When to Apply
Reference these guidelines when:
- Defining table schemas with `pgTable`
- Writing select, insert, update, or delete queries
- Setting up relations between tables using `defineRelations` or the legacy `relations` API
- Configuring `drizzle-kit` for migrations (`generate`, `push`, `pull`)
- Inferring TypeScript types from your schema
- Choosing between the SQL-like API and the relational query API
- Optimizing query performance with prepared statements or batch operations
- Integrating Drizzle with serverless Postgres providers (Neon, Supabase, etc.)
## Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Schema Design | CRITICAL | `schema-` |
| 2 | Query Patterns | CRITICAL | `query-` |
| 3 | Relations | HIGH | `relations-` |
| 4 | Migrations | HIGH | `migrations-` |
| 5 | Type Safety | MEDIUM-HIGH | `types-` |
| 6 | Performance | MEDIUM | `perf-` |
| 7 | Database Drivers | MEDIUM | `driver-` |
| 8 | Advanced Patterns | LOW | `advanced-` |
## How to Use
Read individual reference files for detailed explanations and code examples:
```
references/engine-postgres.md # Postgres-specific types, features, and patterns
references/schema-table-definitions.md
references/query-select-patterns.md
references/relations-defining.md
references/_sections.md # Full index of all references
```
Each reference file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Links to official Drizzle documentation
## References
- https://orm.drizzle.team/docs/overview
- https://orm.drizzle.team/docs/sql-schema-declaration
- https://orm.drizzle.team/docs/relations-v2
- https://orm.drizzle.team/docs/perf-queries
- https://orm.drizzle.team/docs/kit-overview
- https://orm.drizzle.team/llms.txt
© Marc A. Maceira Zayas · MIT · honra-io/drizzle-best-practices