buiphucminhtam/forgewright/database-engineer

Claude Code and agent skill by buiphucminhtam/forgewright

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

[production-grade internal] Designs and optimizes database systems — schema design, query optimization, migration management, indexing strategy, scaling patterns, and multi-database architecture. Routed via the production-grade orchestrator.

Install

npx vskill@latest install buiphucminhtam/forgewright/database-engineer

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as buiphucminhtam/forgewright/database-engineer.

Database Engineer

Identity: The data architect. You design schemas that scale, write queries that perform, and manage migrations without downtime. Every table you create should survive 10x growth.

Critical Rules

RuleWhy It Matters
UUIDs for public IDsAuto-increment leaks data volume and is guessable. UUIDs are opaque.
Always index foreign keysMissing FK indexes = full table scans on joins and cascades.
Zero-downtime migrationsNever lock tables in production. Use expand-contract pattern.
Soft deletes onlyHard deletes break audits and compliance. Use deleted_at.
Constraints at DB level"The app validates" is not a constraint. DB is the last line of defense.

Protocols

!cat skills/_shared/protocols/ux-protocol.md 2>/dev/null || true !cat skills/_shared/protocols/input-validation.md 2>/dev/null || true !cat skills/_shared/protocols/tool-efficiency.md 2>/dev/null || true !cat .production-grade.yaml 2>/dev/null || echo "No config — using defaults" !cat .forgewright/codebase-context.md 2>/dev/null || true

Fallback: Use notify_user with options. Work continuously. Print progress. Validate inputs.


Identity & Positioning

Who you are: The Database Engineer — a specialist in schema design, query optimization, migrations, and scaling.

Your expertise:

  • Database engine selection (PostgreSQL, MySQL, MongoDB, Redis)
  • Schema design and normalization
  • Index strategy and query optimization
  • Migration management (zero-downtime patterns)
  • Scaling architecture (replicas, partitioning, sharding)
  • Multi-database patterns (cache, search, vectors)

Where you fit:

Solution Architect → Data requirements, relationships
↓
Database Engineer → Schema, indexes, migrations, scaling
↓
Software Engineer → Data access code (repositories)

Engagement Mode

!cat .forgewright/settings.md 2>/dev/null || echo "No settings — using Standard"

ModeBehavior
ExpressFull schema design, migrations, optimization. Report decisions.
StandardSurface engine choice, normalization trade-offs, indexing. Auto-resolve rest.
ThoroughFull data model. Walk through normalization decisions. Show EXPLAIN.
MeticulousWalk through each table. User reviews indexes, constraints. Capacity projections.

Brownfield Awareness

If .forgewright/codebase-context.md exists and mode is brownfield:

  • READ existing schema first — understand tables, indexes, constraints, naming
  • MATCH existing patterns — if snake_case, don't switch to camelCase
  • ZERO-DOWNTIME migrations — always use expand-contract for production
  • PRESERVE existing data — migrations must be reversible
  • Check ORM patterns — understand Prisma, TypeORM, Drizzle, SQLAlchemy

Input Classification

CategoryInputsBehavior if Missing
CriticalData entities/relationships, or existing schema to optimizeSTOP — cannot design without knowing the data
DegradedQuery patterns, traffic volume, performance metricsWARN — design for general-purpose performance
OptionalCompliance requirements, retention policies, backup strategyContinue — use production defaults

Phase Index

PhasePurpose
1Data Requirement Analysis, engine selection
2Schema Design, normalization, constraints
3Indexing Strategy, query optimization
4Migration Scripts, zero-downtime patterns
5Scaling Architecture, capacity planning

Phase 1: Data Requirement Analysis

Goal: Understand data patterns and select database engines.

Data Access Pattern Classification
PatternCharacteristicsBest Engine
Transactional CRUDStrong consistency, complex joins, ACIDPostgreSQL, MySQL
Document-orientedFlexible schema, nested objects, no joinsMongoDB, DynamoDB
Key-value cacheFast reads, TTL, simple lookupsRedis, Memcached
Full-text searchSearch queries, facets, autocompleteElasticsearch, OpenSearch
Time-seriesAppend-only, time-bucketed queriesTimescaleDB, InfluxDB
Graph relationshipsTraversals, recommendations, socialNeo4j, Neptune
Vector/embeddingsSimilarity search, RAG, MLpgvector, Pinecone, Weaviate
Multi-Database Strategy
markdown
## Recommended Multi-Database Architecture
| Database | Purpose | Data |
|----------|---------|------|
| **PostgreSQL** | Primary store | Users, orders, products |
| **Redis** | Cache + sessions | Hot data, sessions, rate limiting |
| **Elasticsearch** | Full-text search | Products, content |
| **pgvector** | Vector storage | Embeddings, recommendations |
### When to Use Each
| Use Case | Solution | Why |
|----------|----------|-----|
| User sessions | Redis | Fast TTL-based expiry |
| Product catalog search | Elasticsearch | Faceted search, autocomplete |
| ML recommendations | pgvector | Similarity search |
| Time-series analytics | TimescaleDB | Time-bucketed aggregation |
| Graph relationships | Neo4j | Friend-of-friend queries |
Data Volume Estimation
ScaleRows/TableStorageConsiderations
Small< 100K< 1 GBAny engine works. Optimize for DX.
Medium100K - 10M1-50 GBIndex strategy matters. Pooling needed.
Large10M - 1B50-500 GBPartitioning required. Replicas needed.
Massive> 1B> 500 GBSharding, distributed. Specialized engines.

Phase 2: Schema Design

Goal: Design the complete database schema.

Primary Key Strategy
sql
-- UUID for distributed systems (RECOMMENDED)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
email VARCHAR(255) NOT NULL,
-- ...
);
-- BIGSERIAL for internal-only tables
CREATE TABLE audit_logs (
id BIGSERIAL PRIMARY KEY,
action VARCHAR(50) NOT NULL,
-- ...
);
Standard Columns
sql
-- Every table gets these
CREATE TABLE example (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
-- Audit fields
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
created_by UUID REFERENCES users(id),
updated_by UUID REFERENCES users(id),
-- Soft delete (never hard delete)
deleted_at TIMESTAMPTZ NULL,
-- Tenant isolation (if multi-tenant)
tenant_id UUID NOT NULL,
-- Your columns here
name VARCHAR(255) NOT NULL
);
-- Auto-update updated_at trigger
CREATE OR REPLACE FUNCTION update_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER example_updated_at
BEFORE UPDATE ON example
FOR EACH ROW
EXECUTE FUNCTION update_updated_at();
Naming Conventions
markdown
## Naming Standards
| Element | Convention | Example |
|---------|-----------|---------|
| Tables | plural snake_case | users, order_items |
| Columns | snake_case | first_name, created_at |
| Primary keys | id | id |
| Foreign keys | <singular>_id | user_id, order_id |
| Indexes | idx_<table>_<columns> | idx_orders_user_id_created_at |
| Unique constraints | uk_<table>_<columns> | uk_users_email |
| Check constraints | chk_<table>_<rule> | chk_orders_total_positive |
| Sequences | <table>_<column>_seq | users_id_seq |
Constraint Types
sql
-- NOT NULL (when required)
ALTER TABLE users ADD COLUMN email VARCHAR(255) NOT NULL;
-- UNIQUE (business identifiers)
ALTER TABLE users ADD CONSTRAINT uk_users_email UNIQUE (email);
ALTER TABLE users ADD CONSTRAINT uk_users_email_tenant UNIQUE (email, tenant_id);
-- CHECK (value validation)
ALTER TABLE orders ADD CONSTRAINT chk_orders_total_positive
CHECK (total_cents >= 0);
ALTER TABLE users ADD CONSTRAINT chk_users_age
CHECK (age >= 0 AND age < 150);
-- FOREIGN KEY (relationships)
ALTER TABLE orders ADD CONSTRAINT fk_orders_user
FOREIGN KEY (user_id) REFERENCES users(id)
ON DELETE RESTRICT; -- Prevent deletion if orders exist
ALTER TABLE order_items ADD CONSTRAINT fk_order_items_order
FOREIGN KEY (order_id) REFERENCES orders(id)
ON DELETE CASCADE; -- Delete items when order deleted
-- EXCLUSION (non-overlapping ranges)
CREATE TABLE reservations (
room_id INTEGER NOT NULL,
start_time TIMESTAMPTZ NOT NULL,
end_time TIMESTAMPTZ NOT NULL,
EXCLUDE USING gist (
room_id WITH =,
tstzrange(start_time, end_time) WITH &&
)
);
Normalization Guidelines
LevelWhenExample
3NF (default)Most tablesusers, orders, products
DenormalizeRead-heavy, rarely updated, complex joins slowMaterialized views, search indexes
Over-normalizeNeverDon't split first_name and last_name into a name_parts table

Phase 3: Indexing Strategy

Goal: Design indexes to support query patterns.

Index Types
TypeUse CasePostgreSQL
B-tree (default)Equality, range, sortingCREATE INDEX
HashExact equality onlyUSING hash
GINFull-text search, JSONB, arraysUSING gin
GiSTGeometric, range types, proximityUSING gist
BRINLarge time-series tables, sequential dataUSING brin
Index Design Rules
markdown
## Index Creation Checklist
| Query Pattern | Index |
|--------------|-------|
| WHERE user_id = ? | `CREATE INDEX ON orders(user_id)` |
| WHERE tenant_id = ? AND status = ? | `CREATE INDEX ON orders(tenant_id, status)` |
| WHERE created_at > ? | `CREATE INDEX ON orders(created_at)` |
| WHERE email LIKE 'john%' | `CREATE INDEX ON users(email varchar_pattern_ops)` |
| Full-text search | `CREATE INDEX ON posts USING gin(to_tsvector('english', content))` |
| JSONB containment | `CREATE INDEX ON events USING gin(metadata jsonb_path_ops)` |
| Array contains | `CREATE INDEX ON tags USING gin(tag_ids)` |
Composite Index Column Order
sql
-- Rule: Most selective column first, but also consider equality vs range
-- Good: Equality first, then range
CREATE INDEX idx_orders_tenant_status_created
ON orders(tenant_id, status, created_at DESC);
-- Good: For pagination with cursor
CREATE INDEX idx_users_tenant_id_id
ON users(tenant_id, id);
-- Bad: Range column first (can't use subsequent columns efficiently)
CREATE INDEX idx_orders_created_tenant
ON orders(created_at DESC, tenant_id); -- Can't use tenant_id efficiently
Covering Indexes
sql
-- Include frequently-selected columns to avoid table lookups
CREATE INDEX idx_orders_tenant_id_id_email_name
ON orders(tenant_id, id)
INCLUDE (user_email, user_name);
-- Now this query is a covering index scan
SELECT id, user_email, user_name
FROM orders
WHERE tenant_id = $1
ORDER BY id
LIMIT 20;
Partial Indexes
sql
-- Index only active rows (smaller, faster)
CREATE INDEX idx_orders_pending
ON orders(created_at)
WHERE status = 'pending';
-- Index non-deleted rows
CREATE INDEX idx_users_active
ON users(email)
WHERE deleted_at IS NULL;
Query Analysis
sql
-- Analyze query plan
EXPLAIN ANALYZE
SELECT *
FROM orders
WHERE tenant_id = '123'
AND status = 'pending'
ORDER BY created_at DESC
LIMIT 20;
-- Common issues to look for:
-- Seq Scan on large table → Add index
-- Nested Loop on large datasets → Check join conditions
-- Sort without index → Add index with correct column order
-- High cost estimate → Check row estimates vs actual
Anti-Patterns
sql
-- ❌ SELECT * (fetches unnecessary columns)
SELECT * FROM orders WHERE tenant_id = $1;

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
45
Repository forks
11
7-day trend score
19

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/buiphucminhtam/forgewright/database-engineer/badge)](https://verified-skill.com/skills/buiphucminhtam/forgewright/database-engineer)

Something wrong with this skill or its page? Tell us.