
Database Schema Documentation
- 503 installs
- 305 repo stars
- Updated March 4, 2026
- aj-geddes/useful-ai-prompts
database-schema-documentation is an agent skill that automatically generates clear documentation for database tables, relationships, indexes, constraints, and ERD diagrams.
About
database-schema-documentation is an agent skill from aj-geddes/useful-ai-prompts for creating comprehensive database schema documentation from existing or planned schemas. The skill produces entity relationship diagrams, table definitions, index listings, constraint documentation, and data dictionaries that onboard engineers faster. Developers reach for database-schema-documentation when a schema lacks readable docs, when onboarding requires ERD visuals, or when migrations need accompanying reference material. Output is structured for both human readers and downstream tooling that consumes schema metadata.
- Generates full data dictionaries with column details and descriptions
- Produces Mermaid ER diagrams showing table relationships and cardinalities
- Documents indexes, constraints, foreign keys and migration history
- Creates versioned schema overviews tied to your application context
- Outputs ready-to-use Markdown that can be dropped into your repo docs
Database Schema Documentation by the numbers
- 503 all-time installs (skills.sh)
- Ranked #386 of 1,879 Documentation skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill database-schema-documentationAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 503 |
|---|---|
| repo stars | ★ 305 |
| Last updated | March 4, 2026 |
| Repository | aj-geddes/useful-ai-prompts ↗ |
How do you document a database schema with ERDs?
Automatically generate clear, complete documentation for database tables, relationships, indexes, constraints, and ERDs.
Who is it for?
Developers documenting existing or new database schemas who need ERDs and data dictionaries for team onboarding.
Skip if: Teams that only need backup automation or disaster recovery planning without schema reference docs.
When should I use this skill?
A task requires documenting database tables, relationships, indexes, constraints, or creating ERD diagrams.
What you get
ERD diagrams, table documentation, index and constraint references, and data dictionary files.
- ERD diagrams
- data dictionary
- table and constraint documentation
Files
Database Schema Documentation
Table of Contents
Overview
Create comprehensive database schema documentation including entity relationship diagrams (ERD), table definitions, indexes, constraints, and data dictionaries.
When to Use
- Database schema documentation
- ERD (Entity Relationship Diagrams)
- Data dictionary creation
- Table relationship documentation
- Index and constraint documentation
- Migration documentation
- Database design specs
Quick Start
Minimal working example:
````markdown
Database Schema Documentation
Database: PostgreSQL 14.x Version: 2.0 Last Updated: 2025-01-15 Schema Version: 20250115120000
Overview
This database supports an e-commerce application with user management, product catalog, orders, and payment processing.
Entity Relationship Diagram
erDiagram
users ||--o{ orders : places
users ||--o{ addresses : has
users ||--o{ payment_methods : has
orders ||--|{ order_items : contains
orders ||--|| payments : has
products ||--o{ order_items : includes
products }o--|| categories : belongs_to
products ||--o{ product_images : has
products ||--o{ inventory : tracks
// ... (see reference guides for full implementation)Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| users | users |
| products | products |
| orders | orders |
| order_items | order_items |
| Enum Types | Enum Types, JSONB Structures |
Best Practices
✅ DO
- Document all tables and columns
- Create ERD diagrams
- Document indexes and constraints
- Include sample data
- Document foreign key relationships
- Show JSONB field structures
- Document triggers and functions
- Include migration scripts
- Specify data types precisely
- Document performance considerations
❌ DON'T
- Skip constraint documentation
- Forget to version schema changes
- Ignore performance implications
- Skip index documentation
- Forget to document enum values
Enum Types
Enum Types
-- Order status values
CREATE TYPE order_status AS ENUM (
'pending',
'confirmed',
'processing',
'shipped',
'delivered',
'cancelled',
'refunded'
);
-- Payment status values
CREATE TYPE payment_status AS ENUM (
'pending',
'processing',
'succeeded',
'failed',
'refunded'
);JSONB Structures
shipping_address format
{
"street": "123 Main St",
"street2": "Apt 4B",
"city": "New York",
"state": "NY",
"postalCode": "10001",
"country": "US"
}product_snapshot format
{
"name": "Product Name",
"sku": "PROD-123",
"price": 99.99,
"image": "https://cdn.example.com/product.jpg"
}---
order_items
order_items
Line items for each order.
Columns:
| Column | Type | Null | Default | Description |
|---|---|---|---|---|
| id | uuid | NO | gen_random_uuid() | Primary key |
| order_id | uuid | NO | - | Foreign key to orders |
| product_id | uuid | NO | - | Foreign key to products |
| product_snapshot | jsonb | NO | - | Product data at order time |
| quantity | int | NO | - | Quantity ordered |
| unit_price | decimal(10,2) | NO | - | Price per unit |
| subtotal | decimal(10,2) | NO | - | Line item total |
| created_at | timestamp | NO | now() | Record creation time |
Indexes:
CREATE INDEX idx_order_items_order_id ON order_items(order_id);
CREATE INDEX idx_order_items_product_id ON order_items(product_id);Foreign Keys:
ALTER TABLE order_items
ADD CONSTRAINT fk_order_items_order
FOREIGN KEY (order_id)
REFERENCES orders(id)
ON DELETE CASCADE;
ALTER TABLE order_items
ADD CONSTRAINT fk_order_items_product
FOREIGN KEY (product_id)
REFERENCES products(id)
ON DELETE RESTRICT;Constraints:
ALTER TABLE order_items
ADD CONSTRAINT order_items_quantity_positive
CHECK (quantity > 0);
ALTER TABLE order_items
ADD CONSTRAINT order_items_subtotal_computation
CHECK (subtotal = quantity * unit_price);---
orders
orders
Stores customer orders.
Columns:
| Column | Type | Null | Default | Description |
|---|---|---|---|---|
| id | uuid | NO | gen_random_uuid() | Primary key |
| order_number | varchar(20) | NO | - | Human-readable order ID (unique) |
| user_id | uuid | NO | - | Foreign key to users |
| status | varchar(20) | NO | 'pending' | Order status |
| subtotal | decimal(10,2) | NO | - | Items subtotal |
| tax | decimal(10,2) | NO | 0 | Tax amount |
| shipping | decimal(10,2) | NO | 0 | Shipping cost |
| total | decimal(10,2) | NO | - | Total amount |
| currency | char(3) | NO | 'USD' | Currency code |
| notes | text | YES | - | Order notes |
| shipping_address | jsonb | NO | - | Shipping address |
| billing_address | jsonb | NO | - | Billing address |
| created_at | timestamp | NO | now() | Order creation time |
| updated_at | timestamp | NO | now() | Last update time |
| confirmed_at | timestamp | YES | - | Order confirmation time |
| shipped_at | timestamp | YES | - | Shipping time |
| delivered_at | timestamp | YES | - | Delivery time |
| cancelled_at | timestamp | YES | - | Cancellation time |
Indexes:
CREATE UNIQUE INDEX idx_orders_order_number ON orders(order_number);
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_status ON orders(status);
CREATE INDEX idx_orders_created_at ON orders(created_at);Constraints:
ALTER TABLE orders
ADD CONSTRAINT orders_status_check
CHECK (status IN ('pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled', 'refunded'));
ALTER TABLE orders
ADD CONSTRAINT orders_total_positive
CHECK (total >= 0);Computed Columns:
-- Total is computed from subtotal + tax + shipping
ALTER TABLE orders
ADD CONSTRAINT orders_total_computation
CHECK (total = subtotal + tax + shipping);---
products
products
Stores product catalog information.
Columns:
| Column | Type | Null | Default | Description |
|---|---|---|---|---|
| id | uuid | NO | gen_random_uuid() | Primary key |
| name | varchar(255) | NO | - | Product name |
| slug | varchar(255) | NO | - | URL-friendly name (unique) |
| description | text | YES | - | Product description |
| price | decimal(10,2) | NO | - | Product price in USD |
| compare_at_price | decimal(10,2) | YES | - | Original price (for sales) |
| sku | varchar(100) | NO | - | Stock keeping unit (unique) |
| category_id | uuid | NO | - | Foreign key to categories |
| brand | varchar(100) | YES | - | Product brand |
| active | boolean | NO | true | Product visibility |
| featured | boolean | NO | false | Featured product flag |
| metadata | jsonb | YES | - | Additional product metadata |
| created_at | timestamp | NO | now() | Record creation time |
| updated_at | timestamp | NO | now() | Last update time |
Indexes:
CREATE UNIQUE INDEX idx_products_slug ON products(slug);
CREATE UNIQUE INDEX idx_products_sku ON products(sku);
CREATE INDEX idx_products_category_id ON products(category_id);
CREATE INDEX idx_products_active ON products(active);
CREATE INDEX idx_products_featured ON products(featured) WHERE featured = true;
CREATE INDEX idx_products_metadata ON products USING gin(metadata);Foreign Keys:
ALTER TABLE products
ADD CONSTRAINT fk_products_category
FOREIGN KEY (category_id)
REFERENCES categories(id)
ON DELETE RESTRICT;Full-Text Search:
-- Add full-text search column
ALTER TABLE products ADD COLUMN search_vector tsvector;
-- Create full-text index
CREATE INDEX idx_products_search ON products USING gin(search_vector);
-- Trigger to update search vector
CREATE TRIGGER products_search_vector_update
BEFORE INSERT OR UPDATE ON products
FOR EACH ROW
EXECUTE FUNCTION
tsvector_update_trigger(
search_vector, 'pg_catalog.english',
name, description, brand
);---
users
users
Stores user account information.
Columns:
| Column | Type | Null | Default | Description |
|---|---|---|---|---|
| id | uuid | NO | gen_random_uuid() | Primary key |
| varchar(255) | NO | - | User email (unique) | |
| password_hash | varchar(255) | NO | - | bcrypt hashed password |
| name | varchar(255) | NO | - | User's full name |
| email_verified | boolean | NO | false | Email verification status |
| two_factor_enabled | boolean | NO | false | 2FA enabled flag |
| two_factor_secret | varchar(32) | YES | - | TOTP secret |
| created_at | timestamp | NO | now() | Record creation time |
| updated_at | timestamp | NO | now() | Last update time |
| deleted_at | timestamp | YES | - | Soft delete timestamp |
| last_login_at | timestamp | YES | - | Last login timestamp |
Indexes:
CREATE UNIQUE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_created_at ON users(created_at);
CREATE INDEX idx_users_deleted_at ON users(deleted_at) WHERE deleted_at IS NULL;Constraints:
ALTER TABLE users
ADD CONSTRAINT users_email_format
CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$');
ALTER TABLE users
ADD CONSTRAINT users_name_length
CHECK (length(name) >= 2);Triggers:
-- Update updated_at timestamp
CREATE TRIGGER update_users_updated_at
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();Sample Data:
INSERT INTO users (email, password_hash, name, email_verified)
VALUES
('john@example.com', '$2b$12$...', 'John Doe', true),
('jane@example.com', '$2b$12$...', 'Jane Smith', true);---
#!/bin/bash
# validate-schema.sh - Validate database schema
# Usage: ./validate-schema.sh <schema_file>
set -euo pipefail
SCHEMA_FILE="${{1:?Usage: $0 <schema_file>}}"
echo "Validating schema: $SCHEMA_FILE"
# TODO: Add schema validation
# - Check SQL syntax
# - Verify foreign key references
# - Check index definitions
# - Validate naming conventions
# - Check for missing constraints
echo "Schema validation complete."
-- Migration: [description]
-- Created: [date]
-- TODO: Customize for your migration framework
BEGIN;
-- Up migration
-- TODO: Add schema changes
-- CREATE TABLE IF NOT EXISTS ...
-- ALTER TABLE ...
-- Down migration (rollback)
-- TODO: Add rollback statements
-- DROP TABLE IF EXISTS ...
COMMIT;
Related skills
How it compares
Choose database-schema-documentation over backup skills when the goal is readable schema reference material rather than disaster recovery.
FAQ
What does database-schema-documentation produce?
database-schema-documentation produces ERD diagrams, table definitions, index and constraint documentation, and data dictionaries. The skill turns raw schema structures into readable reference material for engineering teams.
When should developers use database-schema-documentation?
Developers should use database-schema-documentation when documenting an existing schema, creating ERD visuals, or writing table reference docs during migrations. The skill is for documentation, not backup or recovery planning.