Agent-skills-standard database-postgresql

Enforce repository patterns, zero-downtime migrations, and indexing standards for PostgreSQL with TypeORM or Prisma. Use when defining entities, writing migrations, adding RLS policies, or optimizing query performance. (triggers: **/*.entity.ts, prisma/schema.prisma, **/migrations/*.sql, TypeOrmModule, PrismaService, PostgresModule)

install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/database/database-postgresql" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-database-postgresql && rm -rf "$T"
manifest: skills/database/database-postgresql/SKILL.md
source content

PostgreSQL Database Standards

Priority: P0 (FOUNDATIONAL)

Patterns & Architecture

  • Repository Pattern: Isolate database logic. Use
    @InjectRepository()
    or
    PrismaService
    .
  • Relationship Integrity: Avoid redundant raw ID columns. Favor relation properties.

Migrations (Strict Rules)

  • NEVER use
    synchronize: true
    in production.
  • Generation: Modify
    .entity.ts
    -> run
    pnpm migration:generate
    .
  • Zero-Downtime: Use Expand-Contract pattern (Add -> Backfill -> Drop) for destructive changes.
  • RLS:
    typeorm migration:generate
    cannot detect Row-Level Security. Use raw
    queryRunner.query()
    SQL for RLS.

See implementation examples for Expand-Contract migration patterns.

Performance & Gotchas

  • Pagination: Mandatory. Use limit/offset or cursor-based pagination.
  • Indexing: Define indexes in code for frequently filtered columns. RLS columns MUST indexed.
  • Transactions: Use
    QueryRunner
    or
    $transaction
    for multi-step mutations.

Anti-Patterns

  • No N+1 queries: Use query builders or eager-load relations instead of lazy-loading in loops.
  • No heavy RLS joins: Keep RLS predicates simple; move complex logic to query/view layer.
  • No synchronize in production: Always run explicit migrations;
    synchronize: true
    destructive.

References