SkillAgentSearch skills...

db

Use this guide when working with database schema design, migrations, queries, and optimization.

Install / Use

npx skills add sahin/ai-rules

Installs into whichever agent you are using.

About this skill
⚡

Claude Commands

Claude Code slash commands

Quality Score

71/100

Supported Platforms

Claude Code

Our assessment of db

db scores 71/100 on our quality scale, 553rd of 595 Data & Analytics skills we index.

Its Claude Commands is 5.9 KB long, well organised into 26 sections with 9 code examples: a thorough specification that gives an agent plenty to work with.

It has no GitHub stars yet, so there is no community track record; judge it on its content.

Substance
29/30
Structure
20/20
Description
12/15
Adoption
0/20
Freshness
11/15

Maintenance, license and trust

  • The repository was last updated about 5 months ago. That is recent enough to be usable, but agent tooling moves fast, so check the instructions against your agent's current version.
  • Our last check on 2026-10-20 found the source still online.
  • No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
  • Its trust signals score 78/100, with 2 cautions from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.

Safety scan

No issues found

Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.

AI review by kimi-k2.7-code on 2026-09-24. Automated pattern scan on 2026-09-24. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.

db compared with similar skills

All 4 of these similar skills score higher than db; compare them before choosing.

SkillScoreStarsUpdatedFormat
db (this skill)by sahin7105mo agoClaude Commands
claude-memby thedotmack100113.5ktodayCLAUDE.md
taste-skillby Leonxlnx100110.6ktodayCLAUDE.md
Agent-Reachby Panniantong100109.2ktodayCLAUDE.md
Understand-Anythingby Egonex-AI10090.9k10d agoCLAUDE.md

Frequently asked questions

How do I install db?
Run npx skills add sahin/ai-rules. The install tabs above show the steps for each supported agent.
Which AI agents does db work with?
It is written for Claude Code, as a Claude Commands file. Other agents that read the same format can often use it too.
Is db safe to use?
Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It declares no license and scores 78/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
Is db still maintained?
The repository was last updated about 5 months ago. That is recent enough to be usable, but agent tooling moves fast, so check the instructions against your agent's current version.

Database Guide

Use this guide when working with database schema design, migrations, queries, and optimization.

Migration Templates

Create Table Migration

-- migrations/YYYYMMDDHHMMSS_create_<table>.sql

-- UP
CREATE TABLE table_name (
  id SERIAL PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  status VARCHAR(50) NOT NULL DEFAULT 'active',
  is_active BOOLEAN NOT NULL DEFAULT true,
  metadata JSONB,
  created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_table_name_status ON table_name(status);

-- DOWN
DROP TABLE IF EXISTS table_name;

Add Column Migration

-- UP
ALTER TABLE table_name
  ADD COLUMN new_column VARCHAR(100) NOT NULL DEFAULT 'default_value';

CREATE INDEX idx_table_name_new_column ON table_name(new_column);

-- DOWN
DROP INDEX IF EXISTS idx_table_name_new_column;
ALTER TABLE table_name DROP COLUMN IF EXISTS new_column;

Add Foreign Key

-- UP
ALTER TABLE child_table
  ADD COLUMN parent_id INTEGER NOT NULL REFERENCES parent_table(id) ON DELETE CASCADE;

CREATE INDEX idx_child_table_parent_id ON child_table(parent_id);

-- DOWN
DROP INDEX IF EXISTS idx_child_table_parent_id;
ALTER TABLE child_table DROP COLUMN IF EXISTS parent_id;

Zero-Downtime Migration Patterns

Adding a NOT NULL Column

  1. Add column as nullable with default
  2. Backfill existing rows
  3. Add NOT NULL constraint
-- Step 1: Add nullable
ALTER TABLE users ADD COLUMN email_verified BOOLEAN DEFAULT false;

-- Step 2: Backfill
UPDATE users SET email_verified = false WHERE email_verified IS NULL;

-- Step 3: Add constraint
ALTER TABLE users ALTER COLUMN email_verified SET NOT NULL;

Renaming a Column

  1. Add new column
  2. Dual-write to both columns (app change)
  3. Backfill old data
  4. Switch reads to new column (app change)
  5. Stop writing old column (app change)
  6. Drop old column

Dropping a Column

  1. Stop reading the column (app change)
  2. Stop writing the column (app change)
  3. Drop the column in migration

Index Strategy

When to Create Indexes

  • Every foreign key column
  • Columns in WHERE clauses
  • Columns in JOIN conditions
  • Columns in ORDER BY
  • Columns with high selectivity used in filters

Index Types

-- B-tree (default): equality and range queries
CREATE INDEX idx_users_email ON users(email);

-- Composite: multi-column queries (leftmost prefix rule)
CREATE INDEX idx_orders_user_status ON orders(user_id, status);

-- Partial: filtered subset of rows
CREATE INDEX idx_orders_pending ON orders(created_at)
  WHERE status = 'pending';

-- GIN: JSONB and array columns
CREATE INDEX idx_products_tags ON products USING GIN(tags);

-- Unique: enforce uniqueness
CREATE UNIQUE INDEX idx_users_email_unique ON users(email);

Index Anti-Patterns

  • Indexing low-cardinality columns (boolean, status with 2-3 values)
  • Too many indexes on write-heavy tables
  • Unused indexes (check pg_stat_user_indexes)
  • Missing composite index when queries filter on multiple columns

Query Optimization

Use EXPLAIN ANALYZE

EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.created_at > '2024-01-01'
GROUP BY u.id;

What to Look For

  • Seq Scan on large tables: add an index
  • Nested Loop with large outer set: consider Hash Join
  • Sort without index: add index matching ORDER BY
  • High actual rows vs estimated: run ANALYZE to update statistics

Common Optimizations

-- BAD: N+1 query pattern
SELECT * FROM users WHERE id = 1;
SELECT * FROM orders WHERE user_id = 1;
SELECT * FROM orders WHERE user_id = 2;

-- GOOD: JOIN or batch
SELECT u.*, o.*
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.id IN (1, 2);

-- BAD: SELECT *
SELECT * FROM users;

-- GOOD: Select only needed columns
SELECT id, name, email FROM users;

-- BAD: OFFSET for deep pagination
SELECT * FROM posts ORDER BY id LIMIT 20 OFFSET 10000;

-- GOOD: Cursor-based pagination
SELECT * FROM posts WHERE id > :last_id ORDER BY id LIMIT 20;

Performance Targets

  • Simple queries (single table, indexed): < 10ms
  • Standard queries (joins, filters): < 100ms
  • Complex queries (aggregations, subqueries): < 500ms
  • Reports/analytics: < 2s (consider materialized views)

Connection Pooling

// Use a connection pool, never direct connections
const pool = new Pool({
  max: 20,              // Max connections
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 5000,
});

// Always release connections
const client = await pool.connect();
try {
  const result = await client.query('SELECT ...');
  return result.rows;
} finally {
  client.release();
}

Rollback Procedures

Before Any Migration

  1. Verify DOWN migration works on staging
  2. Create database backup: pg_dump -Fc dbname > backup.dump
  3. Test rollback: run DOWN, verify schema, run UP again

Emergency Rollback

# Restore from backup
pg_restore -d dbname --clean backup.dump

# Or run DOWN migration
npm run migrate:down

Rollback Checklist

  • [ ] DOWN migration tested on staging
  • [ ] Backup created before production run
  • [ ] App code compatible with both old and new schema
  • [ ] Rollback time estimated and communicated
  • [ ] Monitoring in place for errors after migration

Data Type Reference

| Use Case | Type | Notes | |----------|------|-------| | Primary key | SERIAL or UUID | UUID for distributed systems | | Short text | VARCHAR(n) | Always set appropriate limit | | Long text | TEXT | Only when no reasonable limit | | Money | DECIMAL(19,4) | Never use FLOAT for money | | Timestamps | TIMESTAMP WITH TIME ZONE | Always include timezone | | Boolean | BOOLEAN | Never CHAR(1) or INT | | JSON data | JSONB | Never JSON (no indexing) | | Enum-like | VARCHAR + CHECK | More flexible than ENUM type | | IP address | INET | Native PostgreSQL type | | Arrays | type[] | Only for simple, small arrays |

Related Skills

View on GitHub
GitHub Stars0
CategoryData
Updated4mo ago
Forks0

Trust signals

78/100

From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.

1 medium1 low1 info