drizzle

Enforces Drizzle ORM schema and query conventions for PostgreSQL tables, indexes, and joins.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/ZubairImtiaz3/Safar-E-Iman-Portal --skill drizzle-zubairimtiaz3
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drizzle
Source: https://github.com/ZubairImtiaz3/Safar-E-Iman-Portal/tree/main/.agents/skills/drizzle
Command: npx skills add https://github.com/ZubairImtiaz3/Safar-E-Iman-Portal --skill drizzle-zubairimtiaz3

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Teams writing Drizzle ORM schemas and queries often drift into inconsistent naming, fragile composite primary keys, loose JSONB typing, and the relational db.query API that generates hard-to-debug lateral joins. This Skill codifies the project's schema and query conventions so every table, index, and query follows the same reviewed patterns. ## Core Features & Use Cases - Schema Conventions: Enforces plural snake_case table names, surrogate primary keys with uniqueIndex for business uniqueness, app-generated text IDs, and timestamps helper spreads. - Column Design Rules: Guides foreign keys with cascade deletes, TypeScript $type value types instead of pgEnum, concrete JSONB interfaces, and JSDoc for non-obvious fields. - Query Style Enforcement: Mandates the db.select() builder API with explicit joins and aggregations instead of the relational findMany/with: API, plus rules for raw SQL, recursive CTEs, and upserts. - Use Case: When adding a new many-to-many junction table like agents_knowledge_bases, the Skill directs you to use a surrogate uuid primary key, a uniqueIndex on the pair, cascade foreign keys, and spread timestamps. ## Quick Start Ask the AI to create a new Drizzle pgTable schema for a workspace-scoped settings table following the project's 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 pgTable schema with proper conventions?

Define tables with plural snake_case names, a single-column surrogate primary key (text ID via idGenerator or uuid), foreign keys with onDelete cascade, and spread the timestamps helper. Put business uniqueness in a uniqueIndex rather than a composite primary key.

Should I use db.select or db.query relational API in Drizzle?

Always use the db.select() builder API with explicit leftJoin and groupBy calls. The relational API (findMany, findFirst, with:) generates complex lateral joins with json_build_array that are fragile and hard to debug.

Why avoid composite primary keys in Drizzle tables?

Composite primary keys lock the uniqueness scope to exact columns, and PK columns cannot be nullable. When scope later grows by a nullable dimension, the entire PK must be rebuilt. A surrogate PK plus uniqueIndex lets uniqueness evolve without a rebuild.

Should I use pgEnum or text columns for status fields in Drizzle?

Default to text or varchar columns with a TypeScript value type via $type instead of pgEnum. Database enums require migrations to add members and make removals awkward, while TS-only types evolve freely in the domain type module.

When is raw SQL acceptable in Drizzle queries?

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

How do I type JSONB columns in Drizzle schemas?

Define a concrete TypeScript interface describing the expected JSON shape and apply it with $type on the jsonb column. Avoid Record<string, unknown>, and do not add speculative metadata columns without a concrete writer.