drizzle

Defines Drizzle ORM schema conventions and query patterns for PostgreSQL tables.

Updated Jan 27, 2026
One-click install
npx skills add https://github.com/SmallAi-API/smaihub --skill drizzle-smallai-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drizzle
Source: https://github.com/SmallAi-API/smaihub/tree/main/.agents/skills/drizzle
Command: npx skills add https://github.com/SmallAi-API/smaihub --skill drizzle-smallai-api

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? It standardizes how teams write Drizzle ORM schemas, queries, and migrations so PostgreSQL tables, indexes, relations, and inferred types stay consistent and safe to evolve. ## Core Features & Use Cases - Schema Conventions: Enforces naming rules, surrogate primary keys, foreign keys, timestamps, typed JSONB columns, and index definitions for new tables. - Query Style Guide: Mandates the db.select() builder API over the relational db.query.* API, with patterns for joins, aggregations, upserts, and raw SQL fallbacks like recursive CTEs. - Migration Workflow: Covers generating migrations with bun run db:generate, renaming files meaningfully, and writing idempotent SQL with IF NOT EXISTS clauses. - Use Case: When adding a new workspace-scoped table, follow the guide to pick the right table name, use a surrogate UUID primary key with a unique index, spread standard timestamps, and generate an idempotent migration. ## Quick Start Ask the AI to create a new Drizzle table schema with proper primary keys, indexes, and a migration following the project conventions.

Frequently Asked Questions about drizzle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a Drizzle table schema for PostgreSQL?

Define tables with pgTable using plural snake_case names, a text or uuid surrogate primary key with $defaultFn, foreign keys with onDelete cascade, and spread standard timestamps from the helpers file. Put business uniqueness in a uniqueIndex rather than a composite primary key.

How to write joins and aggregations with Drizzle ORM?

Use the db.select() builder with explicit leftJoin, groupBy, and count helpers instead of the relational db.query API with findMany or with clauses. The relational API generates fragile lateral joins with json_build_array that are hard to debug.

Should I use composite primary keys in Drizzle tables?

No, use a single-column surrogate primary key and enforce uniqueness with a uniqueIndex. Composite primary keys cannot include nullable columns, so expanding the uniqueness scope later forces a full primary key rebuild migration.

Does Drizzle support PostgreSQL enums for status columns?

The convention is to avoid pgEnum because adding or removing members requires migrations. Use text or varchar columns with a TypeScript value type via $type instead, keeping the value types in a shared domain types module.

How do I generate idempotent Drizzle migrations?

Run bun run db:generate to create the migration, rename the file meaningfully, then edit the SQL to use defensive clauses like ADD COLUMN IF NOT EXISTS, DROP TABLE IF EXISTS, and CREATE INDEX IF NOT EXISTS so migrations can be safely re-run.

When should I use raw SQL instead of Drizzle query builders?

Keep raw SQL only for features Drizzle cannot express, such as recursive CTEs with WITH RECURSIVE. Tighten it by using schema references in interpolations, scoping queries to the user, defining a narrow row interface, and adding regression tests.