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.mdsource content
PostgreSQL Database Standards
Priority: P0 (FOUNDATIONAL)
Patterns & Architecture
- Repository Pattern: Isolate database logic. Use
or@InjectRepository()
.PrismaService - Relationship Integrity: Avoid redundant raw ID columns. Favor relation properties.
Migrations (Strict Rules)
- NEVER use
in production.synchronize: true - Generation: Modify
-> run.entity.ts
.pnpm migration:generate - Zero-Downtime: Use Expand-Contract pattern (Add -> Backfill -> Drop) for destructive changes.
- RLS:
cannot detect Row-Level Security. Use rawtypeorm migration:generate
SQL for RLS.queryRunner.query()
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
orQueryRunner
for multi-step mutations.$transaction
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;
destructive.synchronize: true