Drizzle
Installation
SKILL.md
Schema Definition
- Export every table from schema file — queries fail silently if table isn't exported
- Use
$inferSelectfor query return types,$inferInsertfor insert input — they differ (select has defaults filled, insert has optionals) - Define
relations()in a separate call, not inline with table — Drizzle separates schema from relations
Query Syntax Traps
- Conditions use functions, not objects:
where: eq(users.id, 5)notwhere: { id: 5 }— Prisma syntax doesn't work - Combine conditions with
and()/or():where: and(eq(users.active, true), gt(users.age, 18)) db.query.users.findMany()for relational queries withwith:,db.select().from(users)for SQL-like — mixing them causes type errors
Migrations
drizzle-kit pushis dev-only (destructive) — production needsdrizzle-kit generatethendrizzle-kit migrate- Schema changes require regenerating migrations — editing generated SQL breaks the migration hash
- Set
strict: truein drizzle.config.ts to catch schema drift before it hits production