db

Define Drizzle ORM schemas and execute safe reads and writes against Neon Postgres.

Updated May 19, 2026
One-click install
npx skills add https://github.com/TimeKast/AgendaInteligente --skill db-timekast
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db
Source: https://github.com/TimeKast/AgendaInteligente/tree/main/.agent/skills/domains/db
Command: npx skills add https://github.com/TimeKast/AgendaInteligente --skill db-timekast

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It standardizes how your application defines database schemas, writes safe queries and mutations, and delivers consistent migrations so your Drizzle + Neon Postgres data layer stays reliable as it evolves.

Core Features & Use Cases

  • Schema-first development with derived types: enforce a single source of truth in lib/db/schema/*.ts and generate $inferSelect/$inferInsert types instead of duplicating interfaces.
  • Operational safety patterns: guarantee audit traceability via ...auditFields, prefer soft delete with deletedAt, and keep timestamps in UTC with withTimezone: true.
  • Correctness and performance by default: encourage transactions for multi-step writes and avoid N+1 queries using joins or Drizzle with relations.

Use case example: creating a new domain entity (e.g., an order) with related rows (e.g., order tags) while recording audit fields, ensuring atomicity through db.transaction(), and generating a migration safely from schema changes.

Quick Start

Update your entity schema in lib/db/schema/*.ts, then generate and apply the migration using the Drizzle commands recommended by this skill while following the audit fields, timezone, transaction, and anti-N+1 rules.

Frequently Asked Questions about db

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

FAQPage Schema
How do I generate safe Drizzle ORM migrations for Postgres?

You generate safe Drizzle ORM migrations by updating entity schemas in `lib/db/schema/*.ts` and running Drizzle commands to apply changes while enforcing audit fields, timezone, transaction, and anti-N+1 rules.

How do I derive TypeScript types from a Drizzle schema instead of duplicating interfaces?

You derive TypeScript types from a Drizzle schema by defining a single source of truth in `lib/db/schema/*.ts` and generating `$inferSelect` and `$inferInsert` types instead of duplicating interfaces manually.

What is the best way to handle multi-step database writes in Drizzle to ensure atomicity?

The best way to handle multi-step database writes in Drizzle is to use `db.transaction()` for multi-write workflows, ensuring atomicity and preventing partial data updates if an operation fails midway.

How do I implement soft delete and audit fields in a Drizzle Postgres schema?

You implement soft delete and audit fields in a Drizzle Postgres schema by spreading `...auditFields` for traceability, using `deletedAt` for soft deletes, and keeping timestamps in UTC with `withTimezone: true`.

Does this database schema approach work with Neon Postgres?

Yes, this database schema approach works with Neon Postgres, standardizing how Drizzle ORM executes safe database reads and writes specifically against the Neon Postgres data layer as it evolves.

How do I avoid N+1 queries when using Drizzle ORM relations?

You avoid N+1 queries when using Drizzle ORM by utilizing joins or Drizzle `with` relations to fetch related rows efficiently, adhering to performance guardrails without relying on unsafe raw SQL for user inputs.