Postgresql

From kumaran-is/claude-code-onboarding · View interactive version

Postgresql is an AI agent skill from the GitHub repository kumaran-is/claude-code-onboarding. PostgreSQL-specific schema design reference for advanced data types (ENUM, array, range, network, domain), storage internals (MVCC, HOT updates, TOAST, heap), and advanced constraints (EXCLUDE, generated columns). Use when designing PostgreSQL schemas, choosing data types, working with extensions (p

How to use this skill

Skill file

Iron Law

NO SCHEMA CHANGES WITHOUT READING THE CURRENT MIGRATION HISTORY FIRST — verify actual table definitions (file:line) before proposing any DDL

Check existing migrations, the current schema, and access patterns before designing or modifying any PostgreSQL schema.

PostgreSQL Table Design

Use this skill when

Do not use this skill when

Instructions

  1. Capture entities, access patterns, and scale targets (rows, QPS, retention).
  2. Choose data types and constraints that enforce invariants.
  3. Add indexes for real query paths and validate with EXPLAIN.
  4. Plan partitioning or RLS where required by scale or access control.
  5. Review migration impact and apply changes safely.

Safety

Core Rules

PostgreSQL "Gotchas"

Data Types

Do not use the following data types

Table Types

Row-Level Security

Enable with ALTER TABLE tbl ENABLE ROW LEVEL SECURITY. Create policies: CREATE POLICY user_access ON orders FOR SELECT TO app_users USING (user_id = current_user_id()). Built-in user-based access control at the row level.

Constraints

Indexing

Partitioning

Special Considerations

Update-Heavy Tables

Insert-Heavy Workloads

Upsert-Friendly Design

Safe Schema Evolution

Generated Columns

Extensions

JSONB Guidance

Examples

Users

CREATE TABLE users (
  user_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  email TEXT NOT NULL UNIQUE,
  name TEXT NOT NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX ON users (LOWER(email));
CREATE INDEX ON users (created_at);

Orders

CREATE TABLE orders (
  order_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  user_id BIGINT NOT NULL REFERENCES users(user_id),
  status TEXT NOT NULL DEFAULT 'PENDING' CHECK (status IN ('PENDING','PAID','CANCELED')),
  total NUMERIC(10,2) NOT NULL CHECK (total > 0),
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX ON orders (user_id);
CREATE INDEX ON orders (created_at);

JSONB

CREATE TABLE profiles (
  user_id BIGINT PRIMARY KEY REFERENCES users(user_id),
  attrs JSONB NOT NULL DEFAULT '{}',
  theme TEXT GENERATED ALWAYS AS (attrs->>'theme') STORED
);
CREATE INDEX profiles_attrs_gin ON profiles USING GIN (attrs);
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.