/tsh-stack-postgresql:designing-postgresql-schemasfrom TSH Stack: PostgreSQL
Designs and reviews PostgreSQL table schemas: column types, constraints, keys, and patterns like soft delete, multi-tenancy with RLS, audit columns, optimistic locking, status history, and partitioning.
Ships in TSH Stack: PostgreSQL. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The schema is the one place a rule holds for every writer: every service, script, migration and console session. Constraints the database enforces cannot be forgotten by a code path; rules kept only in application code eventually are.
PostgreSQL 14 to 18; 14 reached end of life in November 2026. Some choices depend on
the version (uuidv7() and virtual generated columns are 18+). Check
SELECT version(); or the project's pinned image and every environment that runs
it, including local and CI. Below 14, stop and say the project is on an unsupported
version; continue only when asked.
PostgreSQL only. If the project's database is MySQL, MariaDB, SQL Server or another engine, say this skill does not apply and stop: types, constraints and their defaults differ by engine.
Read the existing schema and its conventions first: naming, key type, timestamp columns, how tenancy and deletion are already handled. A convention the project already follows outranks this skill's defaults; a second convention beside the first is a finding, not an improvement. When the schema is generated from an ORM's entities, the ORM's own skill owns how to express a choice in that ORM; this skill owns what the resulting table should be.
This skill does not ship the change. A table that already holds data changes through
migrating-postgresql-schemas.
| Severity | Rule |
|---|---|
| MUST | Make a column NOT NULL unless absence is a real, distinct state of the data. |
| MUST | Store points in time as timestamptz. timestamp without time zone is for wall-clock values with no zone, such as a store's opening hour. |
| MUST | Store money as numeric with an explicit scale, or as an integer count of the smallest unit, with the currency stored beside it. Never real, double precision or money. |
| MUST | Declare a foreign key for every reference to another table's row, choose its ON DELETE deliberately, and index the referencing column. |
| MUST | Enforce invariants that must hold for every row with constraints (CHECK, UNIQUE, exclusion), not only in application validation. |
| MUST | Use GENERATED ... AS IDENTITY for integer keys, not serial. |
| NEVER | Store several values in one delimited text column, or a reference in a column with no foreign key because "it could point at several tables". |
| NEVER | Reach for jsonb for attributes that are queried, joined, constrained or present on every row. Those are columns. |
| NEVER | Introduce a second naming, key or timestamp convention into a schema that already has one. |
| Reference | Load when | Covers |
|---|---|---|
| Data types | Choosing a column type or primary key | Text, numbers and money, time, keys (identity, UUIDv4, UUIDv7), booleans and status values, jsonb, arrays, ranges |
| Keys and constraints | Adding a reference, a uniqueness rule or any invariant | Foreign keys and ON DELETE, CHECK, unique and partial unique, exclusion, deferrable constraints, naming |
| Schema patterns | Deletion, tenancy, history, concurrency, flexible attributes or table size is part of the design | Soft delete versus archive, multi-tenancy and RLS, audit columns, optimistic locking, status history, polymorphic relations, partitioning |
Read data-types.md before choosing a primary key: it is the hardest choice to change later.
NOT NULL, a key or a
constraint, from keys-and-constraints.md.varchar(255), timestamp without
zone, missing foreign key indexes) is a finding like any other.optimizing-postgresql-queries.List each finding with the table and column, the invariant or risk, and the corrected DDL. Lead with what lets bad data in (a missing constraint or key, a lossy type), then what will be expensive to change later (key type, tenancy, deletion model), then naming and style. Say plainly when the schema is sound.
What SKILL.md sets; muted values are Claude Code's defaults
Trigger on: designing tables for a feature, choosing a column type or primary key, storing money, time, status values or flexible attributes, deciding between an enum, a CHECK constraint and a lookup table, adding foreign keys and choosing ON DELETE, soft delete versus archiving, multi-tenant data isolation, row-level security, deciding whether to partition a table, polymorphic relations, or reviewing an entity, model or SQL schema for data-integrity gaps. Shipping the change to a live table is migrating-postgresql-schemas; a slow query is optimizing-postgresql-queries.
Three short reads, in order
npx claudepluginhub thesoftwarehouse/agentic-collections --plugin tsh-stack-postgresql3 skills in this plugin
/migrating-postgresql-schemasWrites and reviews PostgreSQL schema migrations that run against a live database without stopping traffic: the lock each DDL statement takes and what it blocks, lock_timeout so a migration waits instead of queueing everyone behind it, expand-and-contract for renames and type changes, NOT VALID constraints validated separately, indexes built CONCURRENTLY outside a transaction, and batched backfills. Use when a migration adds, changes or drops a column, index or constraint on a table that already holds production data, or when reviewing a migration an ORM generated./optimizing-postgresql-queriesFinds and fixes slow PostgreSQL queries from evidence: pg_stat_statements to find what actually costs time, EXPLAIN (ANALYZE, BUFFERS) read node by node, estimate-versus-actual row counts and stale statistics, choosing the index that fits the query (composite column order, partial, covering, GIN, BRIN), and the query shapes that defeat an index: N+1 loops, OFFSET pagination, functions on indexed columns, OR across columns, implicit casts. Use when an endpoint or job is slow because of the database, a query plan needs explaining, or someone proposes adding an index.Other plugins' skills for the same job