drizzle

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

74|11|Updated Jul 4, 2024
One-click install
npx skills add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill drizzle-opensourceagi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drizzle
Source: https://github.com/OpenSourceAGI/qwksearch-research-agent/tree/main/apps/qwk-in-lobe/.agents/skills/drizzle
Command: npx skills add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill drizzle-opensourceagi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Teams writing Drizzle ORM schemas and queries often drift into inconsistent patterns—composite primary keys that block future scope changes, fragile relational API queries, loosely typed JSONB columns, and speculative fields—leading to painful migrations and hard-to-review code. ## Core Features & Use Cases - Schema Conventions: Standardizes pgTable definitions with surrogate primary keys, unique indexes, snake_case naming, timestamp helpers, and typed JSONB columns. - Query Style Enforcement: Mandates the db.select() builder API over the relational db.query API, with patterns for joins, aggregations, one-to-many fetches, and raw SQL fallbacks like recursive CTEs. - Migration-Safe Design Rules: Guides decisions on enums, sentinel values, foreign keys, and junction tables so schemas evolve without destructive rebuilds. - Use Case: When adding a new workspace-scoped table with a many-to-many relation, apply this Skill to generate a surrogate-PK schema with a unique index, typed columns, and a matching select-plus-join query that passes code review. ## Quick Start Use the drizzle skill to write a pgTable schema and select query for a new workspace settings table 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 pgTable schema with proper conventions?

Define tables with plural snake_case names, a single-column surrogate primary key using text with idGenerator or uuid with defaultRandom, 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 and never the db.query relational API like findMany or findFirst with 'with' clauses. The relational API 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 primary key columns cannot be nullable. When scope later grows by a nullable dimension, the entire key must be rebuilt, so use a surrogate key with a uniqueIndex instead.

When should I use pgEnum versus text with $type in Drizzle?

Default to text or varchar columns with a TypeScript value type via $type rather than pgEnum. Database enums require migrations to add members and make removals awkward, so reserve them for effectively immutable value sets.

How do I handle many-to-many junction tables in Drizzle?

Give junction tables a surrogate uuid primary key and enforce pair uniqueness with a uniqueIndex on the two foreign keys. Include cascade delete references and standard timestamps, matching the agents_knowledge_bases pattern.

When is raw SQL acceptable in Drizzle queries?

Raw SQL via execute is acceptable when Drizzle cannot express the query, such as recursive CTEs with WITH RECURSIVE. Keep schema references in interpolations, scope queries to the user, and define a narrow row interface.