
Postgres Drizzle
Apply PostgreSQL and Drizzle ORM best practices when defining schemas, queries, migrations, and performance tuning in app code.
Overview
postgres-drizzle is an agent skill for the Build phase that applies PostgreSQL and Drizzle ORM best practices for schemas, queries, migrations, relations, and performance.
Install
npx skills add https://github.com/ccheney/robust-skills --skill postgres-drizzleWhat is this skill?
- Six reference areas: Schema, Queries, Relations, Migrations, PostgreSQL, Performance
- Schema coverage includes types, constraints, indexes, enums, JSONB, and relations
- Migration workflows documented via drizzle-kit commands and production-oriented patterns
- PostgreSQL 18 features, RLS, partitioning, and full-text search called out in references
- Performance section covers indexing strategies, query optimization, and connection pooling
- 6 topic categories in the coverage table
- 7 reference files plus main SKILL.md and cheatsheet
Adoption & trust: 936 installs on skills.sh; 51 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are adding or changing Postgres data layers but risk weak schemas, migration mistakes, or slow queries without Drizzle-specific conventions.
Who is it for?
Indie developers using Drizzle ORM who want consistent patterns for schema, relations, drizzle-kit, and PG performance in one skill package.
Skip if: Teams on other ORMs only (Prisma-only, raw SQL-only shops with no Drizzle) or frontend-only work with no database layer.
When should I use this skill?
Automatically when writing database schemas, queries, migrations, or any database-related code with PostgreSQL and Drizzle.
What do I get? / Deliverables
You get schema, query, migration, and optimization guidance aligned with Drizzle ORM and PostgreSQL features for production-ready backends.
- Schema and relation definitions
- Query and migration patterns
- Performance and indexing recommendations
Recommended Skills
Journey fit
Build backend is the canonical shelf because the skill activates for database schema, query, and migration work in the product codebase. Backend subphase matches ORM models, relational queries, drizzle-kit migrations, and PG features like RLS and partitioning.
How it compares
Drizzle-focused database skill with split reference docs—not a generic SQL tutorial or unrelated ORM migration guide.
Common Questions / FAQ
Who is postgres-drizzle for?
Solo and small-team builders implementing PostgreSQL persistence with Drizzle ORM who want automatic best-practice nudges during coding.
When should I use postgres-drizzle?
Use during Build backend work whenever you define tables, write relational queries, run drizzle-kit migrations, or tune slow Postgres queries.
Is postgres-drizzle safe to install?
It provides coding patterns only—review the Security Audits panel on this page; apply migrations and RLS policies with your own staging checks.
SKILL.md
READMESKILL.md - Postgres Drizzle
# postgres-drizzle PostgreSQL and Drizzle ORM best practices. This skill activates automatically when writing database schemas, queries, migrations, or any database-related code. ## Topics Covered | Category | Topics | |----------|--------| | **Schema** | Column types, constraints, indexes, enums, JSONB, relations | | **Queries** | Operators, joins, aggregations, subqueries, transactions | | **Relations** | One-to-many, many-to-many, relational queries API | | **Migrations** | drizzle-kit commands, workflows, configuration | | **PostgreSQL** | PG18 features, RLS, partitioning, full-text search | | **Performance** | Indexing strategies, query optimization, connection pooling | ## Example Usage ``` "Create a users table with email and timestamps" "Add a posts table with foreign key to users" "Write a query to get users with their posts" "Set up drizzle migrations for production" "Optimize this slow database query" ``` ## Skill Structure - **[SKILL.md](SKILL.md)** - Main skill file (concise overview) - **Reference Files:** - [SCHEMA.md](references/SCHEMA.md) - Column types, constraints, indexes - [QUERIES.md](references/QUERIES.md) - Query patterns and operators - [RELATIONS.md](references/RELATIONS.md) - Relations API and relational queries - [MIGRATIONS.md](references/MIGRATIONS.md) - drizzle-kit workflows - [POSTGRES.md](references/POSTGRES.md) - PostgreSQL 18 features - [PERFORMANCE.md](references/PERFORMANCE.md) - Optimization and pooling - [CHEATSHEET.md](references/CHEATSHEET.md) - Quick reference ## Quick Start ```typescript import { pgTable, uuid, text, timestamp, index } from 'drizzle-orm/pg-core'; import { relations } from 'drizzle-orm'; import { drizzle } from 'drizzle-orm/postgres-js'; import postgres from 'postgres'; // Schema export const users = pgTable('users', { id: uuid('id').primaryKey().defaultRandom(), email: text('email').notNull().unique(), createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), }, (table) => [ index('users_email_idx').on(table.email), ]); // Connection const client = postgres(process.env.DATABASE_URL!); export const db = drizzle(client, { schema: { users } }); // Query const user = await db.query.users.findFirst({ where: eq(users.email, 'user@example.com'), }); ``` ## Resources - **Drizzle Docs**: https://orm.drizzle.team - **PostgreSQL Docs**: https://www.postgresql.org/docs/18/ # Drizzle + PostgreSQL Quick Reference --- ## Schema Definition ### Column Types ```typescript import { pgTable, uuid, text, varchar, integer, bigint, boolean, timestamp, date, numeric, json, jsonb, pgEnum, serial } from 'drizzle-orm/pg-core'; // Primary Keys id: uuid('id').primaryKey().defaultRandom(), // UUIDv4 id: uuid('id').primaryKey().default(sql`uuidv7()`), // UUIDv7 (PG18+) id: integer('id').primaryKey().generatedAlwaysAsIdentity(), // Identity id: serial('id').primaryKey(), // Serial (legacy) // Strings name: text('name').notNull(), email: varchar('email', { length: 255 }).unique(), // Numbers age: integer('age'), price: numeric('price', { precision: 10, scale: 2 }), count: bigint('count', { mode: 'number' }), // Boolean active: boolean('active').default(true), // Timestamps createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), updatedAt: timestamp('updated_at', { withTimezone: true }).$onUpdate(() => new Date()), // JSON data: jsonb('data').$type<{ key: string }>(), // Arrays tags: text('tags').array(), ``` ### Constraints ```typescript email: text('email').notNull().unique(), status: text('status').notNull().default('pending'), price: numeric('price').check(sql`price > 0`), // Foreign Key authorId: uuid('author_id').references(() => users.id, { onDelete: 'cascade' }), ``` ### Indexes ```typescript }, (table) => [ index('idx_name').on(table.column), // B-tree uniqueIndex('idx_unique').on(table.column), // Unique index('idx_composite').on