Skip to content
Skills Library
Programming · Planning

database-schema-designer

/database-schema-designer

Use this skill when designing or reviewing database schemas for SQL and NoSQL databases. Covers normalization, indexing strategy, migration management with rollback safety, query optimization, and multi-tenant patterns. Supports PostgreSQL, MySQL, SQLite, MongoDB, and Vitess.

Licence
MIT
Last repository change
28.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
6
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 28.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use this skill when designing or reviewing database schemas for SQL and NoSQL databases. Covers normalization, indexing strategy, migration management with rollback safety, query optimization, and multi-tenant patterns. Supports PostgreSQL, MySQL, SQLite, MongoDB, and Vitess.

Original author description

Use this skill when designing or reviewing database schemas for SQL and NoSQL databases. Covers normalization, indexing strategy, migration management with rollback safety, query optimization, and multi-tenant patterns. Supports PostgreSQL, MySQL, SQLite, MongoDB, and Vitess.

How it works

  1. When to Use This Skill
  2. Safety Rules (Risk Tier L2)
  3. Design Methodology
  4. NoSQL Design Patterns
  5. Platform Notes
Original SKILL.md headings · 252 lines, 1,365 words
SKILL.md preview
---
name: database-schema-designer
description: >-
  Use this skill when designing or reviewing database schemas for SQL and NoSQL
  databases. Covers normalization, indexing strategy, migration management with
  rollback safety, query optimization, and multi-tenant patterns. Supports
  PostgreSQL, MySQL, SQLite, MongoDB, and Vitess.
version: 1.0.0
platforms: [openclaw, claude, codex, cursor, gemini, copilot, opencode, windsurf]
author:
  name: Skill Foundry (Forge)
  source: PlanetScale Database Skills, Supabase Agent Skills, softaworks/agent-toolkit
license: MIT
risk_tier: L2
tags: [database, schema, sql, nosql, postgres, mysql, migration, optimization, design]
requires:
  binaries: []
---

# Database Schema Designer

Design production-ready database schemas with built-in best practices.
Covering SQL normalization, indexing strategy, migration management with
safe rollback patterns, query optimization, and multi-tenant architecture
patterns across PostgreSQL, MySQL, SQLite, MongoDB, and Vitess.

## When to Use This Skill

Use this skill when:
- Designing a new database schema from scratch
- Reviewing an existing schema for performance or correctness
- Planning a database migration with safe rollback
- Optimizing slow queries on a production database
- Converting between database engines (MySQL → PostgreSQL, etc.)
- Designing multi-tenant data architectures
- Any request like "design a schema for X", "review my database",
  "optimize this query", "create migrations", "normalize this table"

## Safety Rules (Risk Tier L2)

Database operations can be destructive. This skill enforces:

1. **Never DROP without backup** — Always generate backup commands first
2. **Always generate rollback** — Every migration includes verified reversal
3. **Test migrations on staging** — Never run directly on production
4. **Lock-aware design** — Schema changes must consider lock duration
5. **Data integrity first** — Validate before and after every migration
6. **No data loss** — Backfill before dropping columns, migrate before deleting

## Design Methodology

### Phase 1: Domain Modeling

Start with entities, not tables. Map the domain before writing DDL:

```
DOMAIN CANVAS:
├── Entities: What things exist? (User, Order, Product, Invoice)
├── Relationships: How do they connect? (one-to-many, many-to-many)
├── Attributes: What properties do they have?
├── Constraints: What must always be true?
├── Access Patterns: What queries will run most often?
└── Growth Projections: How many rows? At what rate?
```

### Phase 2: Schema Design — SQL

**Normalization checklist:**
- [ ] 1NF: Atomic columns, no repeating groups
- [ ] 2NF: No partial dependencies on composite keys
- [ ] 3NF: No transitive dependencies
- [ ] BCNF: Every determinant is a candidate key (when needed)
- [ ] Denormalize intentionally (document why, measure benefit)

**Example: E-Commerce Schema**

```sql
-- Users table (normalized, with soft delete)
CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    email TEXT NOT NULL UNIQUE,
    name TEXT NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    deleted_at TIMESTAMPTZ  -- soft delete
);
CREATE INDEX idx_users_email ON users(email) WHERE deleted_at IS NULL;

-- Products with inventory tracking
CREATE TABLE products (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    sku TEXT NOT NULL UNIQUE,
    name TEXT NOT NULL,
    price_cents INTEGER NOT NULL CHECK (price_cents >= 0),
    inventory_count INTEGER NOT NULL DEFAULT 0,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_products_sku ON products(sku);

-- Orders with status state machine
CREATE TYPE order_status AS ENUM (
    'pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled'
);

CREATE TABLE orders (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id),
    status order_status NOT NULL DEFAULT 'pending',
    total_cents INTEGER NOT NULL DEFAULT 0,
    shipping_address JSONB NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_status ON orders(status)
    WHERE status IN ('pending', 'processing');

-- Order items (many-to-many with quantities)
CREATE TABLE order_items (
    order_id UUID NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
    product_id UUID NOT NULL REFERENCES products(id),
    quantity INTEGER NOT NULL CHECK (quantity > 0),
    unit_price_cents INTEGER NOT NULL,
    PRIMARY KEY (order_id, product_id)
);
```

### Phase 3: Indexing Strategy

**The Index Selection Algorithm:**

1. **WHERE clause columns** → Candidate for index
2. **JOIN columns** → Index foreign keys
3. **ORDER BY columns** → Consider composite with WHERE cols
4. **SELECT columns** → Consider covering indexes
5. **Cardinality check** → Don't index low-cardinality columns alone

**Index types by database:**

| Database | Index Types | When to Use |
|----------|-------------|-------------|
| PostgreSQL | B-tree (default), Hash, GiST, GIN, BRIN, SP-GiST | B-tree for equality/range; GIN for full-text/arrays; BRIN for large sequential data |
| MySQL/InnoDB | B-tree (clustered PK), Full-text, Spatial | B-tree for most cases; Full-text for text search |
| SQLite | B-tree (default) | All standard cases |
| MongoDB | Single-field, Compound, Multikey, Text, Geospatial, Hashed, TTL | Compound for common queries; TTL for expiring data |

**Index anti-patterns:**
- Indexing every column "just in case" — wastes write performance
- Missing composite index leading column — index on (a, b) doesn't help queries on b alone
- Redundant indexes — index on (a, b) makes index on (a) redundant
- Unused indexes — audit with `pg_stat_user_indexes` or `sys.dm_db_index_usage_stats`

### Phase 4: Migration Design

**Migration file structure:**
```sql
-- migrations/001_add_user_preferences.sql
-- UP: Forward migration (what to apply)
-- DOWN: Rollback migration (how to undo)

-- UP MIGRATION
BEGIN;
CREATE TABLE user_preferences (
    user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
    theme TEXT NOT NULL DEFAULT 'light',
    notifications JSONB NOT NULL DEFAULT '{}',
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Backfill existing users with defaults
INSERT INTO user_preferences (user_id)
SELECT id FROM users
ON CONFLICT (user_id) DO NOTHING;
COMMIT;

-- DOWN MIGRATION
-- BEGIN;
-- DROP TABLE IF EXISTS user_preferences;
-- COMMIT;
```

**Safe migration rules:**

1. **Add columns** → Safe (nullable with default)
2. **Drop columns** → Three-step: stop writing → backfill → drop
3. **Rename columns** → Two-step: add new + dual-write → drop old
4. **Change type** → Add new column → backfill → switch reads → drop old
5. **Add NOT NULL** → Add with default → backfill nulls → add constraint
6. **Create index** → Use CONCURRENTLY (PostgreSQL) or ONLINE (MySQL 8+)
7. **Drop index** → Use CONCURRENTLY if available
8. **Add foreign key** → Validate existing data first, validate constraint

### Phase 5: Query Optimization

**The EXPLAIN-based optimization workflow:**

1. Run `EXPLAIN (ANALYZE, BUFFERS)` on the slow query
2. Identify the bottleneck: sequential scan? nested loop? sort?
3. Check if statistics are up to date: `ANALYZE table_name`
4. Consider: new index, query rewrite, schema change, or config tuning
5. Test and measure improvement (not just EXPLAIN cost, actual timing)

**Common optimization patterns:**

| Problem | Symptom | Fix |
|---------|---------|-----|
| Missing index | Seq Scan on large table | Add covering index for WHERE + JOIN + SELECT |
| N+1 queries | Many small queries | Use JOIN or batch load |
| Over-fetching | SELECT * on wide tables | Select only needed columns |
| Lock contention | UPDATE waiting on locks | Batch updates, use SKIP LOCKED |
| Statistics stale | Planner choosing wrong plan | ANALYZE table; adjust default_statistics_target |

### Phase 6: Multi-Tenant Architecture

| Pattern | Description | Best For | Trade-offs |
|---------|-------------|----------|------------|
| **Database per tenant** | Separate DB per customer | High security, compliance | Many connections, harder cross-tenant queries |
| **Schema per tenant** | Separate schema per customer | Medium security, shared DB | Easier backups, moderate isolation |
| **Row-level (shared)** | tenant_id column everywhere | Simplicity, shared resources | Weakest isolation, query complexity |
| **Hybrid** | Combine patterns by tier | Enterprise customers get isolation | Operational complexity |

## NoSQL Design Patterns

### MongoDB Schema Design

```javascript
// Denormalized by access pattern
db.products.insertOne({
  _id: ObjectId(),
  name: "Widget",
  price: 9.99,
  // Embedded reviews (accessed together)
  reviews: [
    { user: "alice", rating: 5, comment: "Great!" },
    { user: "bob", rating: 4, comment: "Good value" }
  ],
  // Reference pattern for frequently-updated data
  inventory_warehouse_id: ObjectId("...")
});
```

**MongoDB data modeling rules:**
- Embed for "contains" relationships (order → line items)
- Reference for "uses" relationships (order → product)
- Embed when data is read together, updated together
- Reference when data is shared across documents
- Size limit: documents must be under 16MB

### Key-Value (Redis) Design

```
# Session store with TTL
SETEX session:abc123 3600 '{"user_id": 42, "role": "admin"}'

# Rate limiting with sliding window
INCR rate:user:42
EXPIRE rate:user:42 60

# Leaderboard with sorted sets
ZADD leaderboard:weekly 1000 player:42 950 player:17
ZREVRANGE leaderboard:weekly 0 9 WITHSCORES
```

## Platform Notes

- **All platforms:** This skill provides declarative knowledge — the agent
  applies patterns using its existing database tools and query capabilities.
- **Risk tier L2:** Schema design is read-heavy during design phases.
  Migration execution requires human approval gates.
- **Database-specific tools:** The skill supports SQL command generation but
  defers to the agent's MCP or native database tools for actual execution.
Files in this package (6)
  • CHANGELOG.md 1 KB
  • LICENSE 1 KB
  • SKILL.md 10 KB
  • corrections.log 1 KB
  • evals/cases.md 3 KB
  • evals/evals.json 3 KB

Versions

RepositoryScoreLicence
This page · JPeetz/agent-skills100MIT
TerminalSkills/skills100Apache-2.0
jeremylongshore/tons-of-skills-marketplace100MIT
dannykkh/skill-olympus100MIT
Qadri-uk/claude-skills100MIT
alirezarezvani/claude-skills100MIT
borghei/Claude-Skills100MIT
OneWave-AI/claude-skills100MIT
tmj-90/gaffer100Apache-2.0

Database snapshot: 13.11.2026 · package version 804f8bb66200 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100database-design
    Database schema design, optimization, and migration patterns for PostgreSQL, MySQL, and NoSQL databases. Use for designing schemas, writing migrations, or optimizing queries.
  • 100database-design
    Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.
  • 100database-designer
    Use when the user asks to design database schemas, plan data migrations, optimize queries, choose between SQL and NoSQL, or model data relationships.
  • 100database-designer
    Design a database schema: tables, relationships, indexes, normalization, SQL vs NoSQL, migration plans. Use whenever the user asks how to structure their data, which database to pick, or before writing DDL. Only invoke via the orcinus router.
  • 100database-designer
    Use when the user asks to design database schemas, plan data migrations, optimize queries, choose between SQL and NoSQL, or model data relationships.
  • 100db-migrator
    Database schema migration, versioning, and rollback management for SQL and NoSQL databases. Use when: (1) creating database migrations, (2) modifying table schemas, (3) adding/removing columns, (4) creating indexes, (5) data migrations, (6) rollback operations, (7)…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.