sk-db

Standardize Drizzle database schemas and mutations with audit fields, soft delete, dual IDs, and pagination.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the inconsistency and fragility of database code by standardizing audit fields, soft-deletes, dual human/technical IDs, pagination, deletion eligibility, and the migration workflow so your Next.js/Drizzle projects behave predictably in production.

Core Features & Use Cases

  • Enforces mandatory audit fields: Adds createdAt/createdBy/modifiedAt/modifiedBy via auditFields and documents how to populate them using the kit’s injected userId from server action wrappers.
  • Implements soft delete conventions: Adds deletedAt/deletedBy with softDeleteFields and guarantees reads filter out deleted rows via notDeleted().
  • Standardizes dual-ID human identifiers: Provides generateHumanId, atomic sequence-based getNextHumanId, gap-resilient getNextHumanIdSeq, and race-safe withHumanIdRetry() including the required SAVEPOINT behavior when called inside a parent transaction.
  • Provides safe pagination primitives: Uses parsePaginationParams, buildPaginationSQL, and createCachedCount with revalidation tagging to prevent stale totals.
  • Adds hard-delete eligibility checks: Uses canHardDeleteUser to prevent permanent deletion when downstream references exist.
  • Gives repeatable migration and DB inspection workflow: Establishes db:generate → review SQL → db:migrate, and read-only inspection via pnpm db:query.

Quick Start

Use the sk-db helpers when creating new Drizzle schema files and mutations to ensure every table includes auditFields, applies softDeleteFields where appropriate, and uses the kit’s pagination, human-id, and migration conventions.

Frequently Asked Questions about sk-db

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

FAQPage Schema
How do I enforce audit fields and soft delete in Drizzle ORM schema definitions?

To enforce audit fields and soft delete in Drizzle ORM, use helper modules that add createdAt/createdBy and deletedAt/deletedBy columns to schema definitions, ensuring reads filter out deleted rows via a notDeleted() helper.

What is the best way to generate race-safe sequence-based human IDs in Postgres?

Generating race-safe human IDs in Postgres requires atomic sequence functions wrapped in a retry mechanism that uses SAVEPOINT behavior when called inside a parent transaction to handle sequence gaps safely.

How do I implement safe pagination with cached counts in a Next.js application?

Implement safe pagination by parsing parameters, building pagination SQL, and using a cached count function with revalidation tagging to prevent stale totals across your Next.js application database queries.

Does this database pattern approach require a specific migration workflow?

Yes, this database pattern approach requires a repeatable migration workflow: generate migration SQL, manually review the output, apply the migration, and perform read-only data inspection via a dedicated query runner.

When should I prevent hard deletion of database rows in Postgres?

You should prevent hard deletion of database rows in Postgres when downstream references exist, using eligibility checks that verify no dependent records are present before allowing permanent deletion.

Can I use standard Drizzle schema definitions without injected userId for audit tracking?

No, populating audit fields requires using injected userId from server action wrappers to automatically track createdBy and modifiedBy values, ensuring consistent attribution across all database mutations.