"PostgreSQL-specific schema and data-layer engineering: DDL, data types, constraints, indexing, JSONB, partitioning, RLS, and safe schema evolution. Use when targeting Postgres specifically."
Resources
1Install
npx skillscat add dmonteroh/curated-agent-skills/postgresql-engineering Install via the SkillsCat registry.
SKILL.md
PostgreSQL Engineering
Use this skill for Postgres-specific schema/data-layer decisions (not just SQL query authoring).
Use this skill when
- Designing Postgres schemas, constraints, and indexing strategy
- Choosing Postgres data types (JSONB, arrays, enums, money/time types)
- Planning partitioning or RLS policies
- Reviewing schema changes for safety and operational impact
Do not use this skill when
- You are targeting a non-PostgreSQL database
- You only need query authoring/tuning
- You need DB-agnostic modeling guidance
Workflow (Deterministic)
- Capture requirements
- Ask for entities, invariants, access paths, scale targets, and deployment constraints.
- If any of these are missing, pause and request the specific inputs.
- Output: Requirements summary + assumptions list.
- Model schema + constraints
- Map entities to tables; map invariants to NOT NULL, UNIQUE, CHECK, and FK constraints.
- If an invariant cannot be enforced by constraints, call it out explicitly.
- Output: Table/column list with constraints tied to each invariant.
- Choose data types and storage
- Use Postgres-native types intentionally (TIMESTAMPTZ, NUMERIC, JSONB, enums).
- If global/opaque IDs are required, choose UUID; otherwise prefer BIGINT identity.
- If attributes are frequently filtered/sorted, model them as columns; if truly unstructured, use JSONB.
- Output: Data type decisions + rationale per column.
- Design indexes for access paths
- Add indexes for join keys, common filters/sorts, and uniqueness requirements.
- If JSONB containment is a primary access pattern, add GIN indexes.
- Output: Index list mapped to queries/access paths.
- Plan operational features
- If data is time-sliced and large, consider partitioning; otherwise avoid it.
- If per-tenant or per-user access isolation is required, design RLS policies.
- Output: Partitioning/RLS decision and configuration outline.
- Plan safe schema evolution
- Use expand/contract for breaking changes; avoid long table rewrites.
- If creating large indexes, use CREATE INDEX CONCURRENTLY with a rollback plan.
- Output: Migration plan with rollout, rollback, and verification steps.
Common pitfalls
- Missing indexes on foreign keys (Postgres does not add them automatically).
- Using JSONB for fields that need frequent filtering or sorting.
- Adding NOT NULL columns with volatile defaults that rewrite large tables.
- Relying on UNIQUE with NULLs when single-null enforcement is required.
Examples
Example prompt
"Design a Postgres schema for orders, users, and line items with a safe migration plan."
Example response (abridged)
- Requirements summary + assumptions
- Entities: users, orders, line_items; access paths for user history and order lookup.
- Assumptions: moderate write load, quarterly schema changes.
- Schema proposal
users,orders,line_itemswith NOT NULL, UNIQUE, FK, and CHECK constraints tied to invariants.
- Data type decisions
- BIGINT identity PKs, NUMERIC for money, TIMESTAMPTZ for event time.
- Index plan
orders(user_id, created_at),line_items(order_id).
- Operational features
- No partitioning; RLS not required.
- Migration plan
- Expand/contract steps with rollback and verification queries.
Output Contract (Always)
Provide a report using this exact structure and ordering:
- Requirements summary + assumptions
- Schema proposal (tables/columns/constraints tied to invariants)
- Data type decisions (with rationale)
- Index plan (tied to access paths)
- Operational features (partitioning/RLS if applicable)
- Migration plan (rollout, rollback, verification)
References (Optional)
- Reference index:
references/README.md - Full Postgres playbook (types, indexing, JSONB, migrations):
references/playbook.md