Token导航 LogoToken导航

Agent Skill · 研究检索

database-design-expert(数据库设计专家)

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

database-design-expert 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为只读;许可证为 MIT,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 4,412。

总安装 32,666周安装 809GitHub Stars 38下载 4,890核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:database-design-expert(数据库设计专家)
来源仓库:https://github.com/martinholovsky/claude-skills-generator
仓库路径:skills/database-design-expert
安装命令:
npx skills add https://github.com/martinholovsky/claude-skills-generator --skill 'Database Design Expert'
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/martinholovsky/claude-skills-generator --skill 'Database Design Expert'

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

提供数据库设计领域的专家级指导与最佳实践参考。适用于复杂关系建模、高性能查询设计和敏感数据处理场景。使用前必须阅读相关参考文件以确保符合安全与设计规范。操作前需评估是否调用更专业的子领域专家(如 PostgreSQL 或 MongoDB)。

database-design-expert 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/database-design-expert

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/martinholovsky/claude-skills-generator --skill…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它标注为只读,先用只读任务试一次,确认行为符合预期再扩大使用范围。

常见问题

6 条

database-design-expert 怎么安装?

在终端执行 npx skills add https://github.com/martinholovsky/claude-skills-generator --skill 'Database…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

database-design-expert 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

database-design-expert 需要什么权限?

权限级别是只读。该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

database-design-expert 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

database-design-expert 用的人多吗?

公开数据是累计安装 32,666 次,近一周安装 809 次,下载 4,890 次,GitHub 38 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

database-design-expert 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
database-design-expert

数据库设计专家 · 本页

32,66638只读MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Database Design Expert

0. Mandatory Reading Protocol

CRITICAL: Before implementing ANY database schema, you MUST read the relevant reference files:

Trigger Conditions for Reference Files

Read references/advanced-patterns.md WHEN:

  • Designing schemas for new features
  • Implementing complex relationships (many-to-many, polymorphic)
  • Setting up inheritance patterns
  • Designing for high-performance queries

Read references/security-examples.md WHEN:

  • Storing sensitive user data
  • Designing audit trails
  • Implementing access control at database level
  • Handling PII or financial data

1. Overview

Risk Level: MEDIUM

Justification: Database schema design impacts data integrity, query performance, and application security. Poor design can lead to data corruption, performance bottlenecks, and difficulty in maintaining data consistency. Schema changes in production require careful migration planning.

You are an expert in database schema design, specializing in:

  • Normalization with appropriate denormalization for performance
  • Indexing strategies for query optimization
  • Full-Text Search (FTS5) schema design
  • Constraint design for data integrity
  • Migration-friendly schemas that evolve safely

Core Principles

  1. TDD First - Write tests for schema and queries before implementation
  2. Performance Aware - Design for query patterns, optimize indexes, profile regularly
  3. Normalize then denormalize - Start with 3NF, denormalize based on measured needs
  4. Constraint everything - Use database constraints as the last line of defense
  5. Migration safety - All schema changes must be reversible and tested

Primary Use Cases

  • Desktop application data modeling
  • Local-first application architecture
  • Efficient search and retrieval patterns
  • Audit and history tracking
  • Configuration and settings storage

2. Core Responsibilities

2.1 Data Integrity Principles

  1. Normalize to eliminate redundancy - Then denormalize strategically for performance
  2. Use appropriate constraints - Primary keys, foreign keys, unique, check constraints
  3. Design for referential integrity - Foreign keys with appropriate cascade rules
  4. Plan for schema evolution - Design migrations that preserve data

2.2 Performance Design Principles

  1. Index for your queries - Analyze query patterns before indexing
  2. Avoid over-indexing - Each index slows writes
  3. Use covering indexes - Include columns in index to avoid table lookups
  4. Design for locality - Keep related data together

3. Technical Foundation

3.1 SQLite Data Types

SQLite TypeUse ForNotes
INTEGERIDs, counts, booleansPRIMARY KEY for auto-increment
TEXTStrings, JSON, UUIDsNo length limit
REALFloating point8-byte IEEE float
BLOBBinary dataFiles, encrypted data
NUMERICDates, decimalsStored as most efficient type

3.2 Normalization Levels

FormDescriptionWhen to Use
1NFAtomic values, no repeating groupsAlways
2NF1NF + no partial dependenciesMost tables
3NF2NF + no transitive dependenciesDefault choice
BCNF3NF + every determinant is a keyComplex relationships

4. Implementation Patterns

4.1 Base Table Template

CREATE TABLE entities (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL CHECK(length(name) BETWEEN 1 AND 255),
    email TEXT UNIQUE NOT NULL CHECK(email LIKE '%_@__%.__%'),
    status TEXT NOT NULL DEFAULT 'active' CHECK(status IN ('active', 'inactive', 'deleted')),
    created_at TEXT NOT NULL DEFAULT (datetime('now')),
    deleted_at TEXT
);

CREATE INDEX idx_entities_status ON entities(status) WHERE deleted_at IS NULL;

4.2 Relationship Patterns

One-to-Many
CREATE TABLE documents (
    id INTEGER PRIMARY KEY, user_id INTEGER NOT NULL, title TEXT NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX idx_documents_user ON documents(user_id);
Many-to-Many
CREATE TABLE document_tags (
    document_id INTEGER NOT NULL, tag_id INTEGER NOT NULL,
    PRIMARY KEY (document_id, tag_id),
    FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,
    FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
);
CREATE INDEX idx_doctags_tag ON document_tags(tag_id);
Self-Referential (Hierarchies)
-- Tree structure (adjacency list)
CREATE TABLE categories (
    id INTEGER PRIMARY KEY,
    parent_id INTEGER REFERENCES categories(id) ON DELETE CASCADE,
    name TEXT NOT NULL
);
CREATE INDEX idx_categories_parent ON categories(parent_id);

4.3 Full-Text Search Schema

-- Content table
CREATE TABLE articles (
    id INTEGER PRIMARY KEY, title TEXT NOT NULL, body TEXT NOT NULL,
    created_at TEXT DEFAULT (datetime('now'))
);

-- FTS5 virtual table
CREATE VIRTUAL TABLE articles_fts USING fts5(
    title, body, content=articles, content_rowid=id,
    tokenize='porter unicode61', prefix='2,3'
);

-- Sync triggers (INSERT, UPDATE, DELETE)
CREATE TRIGGER articles_ai AFTER INSERT ON articles BEGIN
    INSERT INTO articles_fts(rowid, title, body) VALUES (new.id, new.title, new.body);
END;
-- Similar triggers needed for UPDATE and DELETE

4.4 Audit Trail Pattern

CREATE TABLE accounts (id INTEGER PRIMARY KEY, name TEXT NOT NULL, balance REAL DEFAULT 0);

CREATE TABLE accounts_audit (
    id INTEGER PRIMARY KEY, account_id INTEGER NOT NULL,
    field_name TEXT NOT NULL, old_value TEXT, new_value TEXT,
    changed_at TEXT DEFAULT (datetime('now')),
    FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
);

CREATE TRIGGER accounts_audit_update AFTER UPDATE ON accounts BEGIN
    INSERT INTO accounts_audit (account_id, field_name, old_value, new_value)
    SELECT new.id, 'balance', old.balance, new.balance WHERE old.balance != new.balance;
END;

CREATE INDEX idx_audit_account ON accounts_audit(account_id, changed_at DESC);

5. Security Standards

5.1 Data Integrity Controls

-- Numeric, string format, and enum constraints
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    email TEXT UNIQUE NOT NULL CHECK(email LIKE '%_@__%.__%'),
    phone TEXT CHECK(phone IS NULL OR phone GLOB '+[0-9]*'),
    status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'active', 'deleted'))
);

-- Date range validation
CREATE TABLE events (
    id INTEGER PRIMARY KEY, start_date TEXT NOT NULL, end_date TEXT NOT NULL,
    CHECK(end_date >= start_date)
);

5.2 Soft Delete Pattern

CREATE TABLE documents (id INTEGER PRIMARY KEY, title TEXT NOT NULL, deleted_at TEXT);
CREATE VIEW active_documents AS SELECT * FROM documents WHERE deleted_at IS NULL;
CREATE INDEX idx_documents_active ON documents(title) WHERE deleted_at IS NULL;

6. Indexing Strategies

-- Single column for equality/range | Composite (equality first, then range)
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at DESC);

-- Covering index (avoid table lookup) | Partial index (filtered queries)
CREATE INDEX idx_users_cover ON users(email, name, status);
CREATE INDEX idx_active_users ON users(email) WHERE status = 'active';

-- Expression index | Always verify with EXPLAIN
CREATE INDEX idx_users_lower ON users(LOWER(email));
EXPLAIN QUERY PLAN SELECT * FROM users WHERE email = ?;

7. Implementation Workflow (TDD)

Step 1: Write Failing Tests First

# tests/test_schema.py
import pytest
import sqlite3

@pytest.fixture
def db():
    conn = sqlite3.connect(':memory:')
    conn.execute("PRAGMA foreign_keys = ON")
    yield conn
    conn.close()

class TestUserSchema:
    def test_email_uniqueness(self, db):
        db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT UNIQUE NOT NULL)")
        db.execute("INSERT INTO users (email) VALUES ('test@example.com')")
        with pytest.raises(sqlite3.IntegrityError):
            db.execute("INSERT INTO users (email) VALUES ('test@example.com')")

    def test_email_format_constraint(self, db):
        db.execute("""CREATE TABLE users (
            id INTEGER PRIMARY KEY,
            email TEXT UNIQUE NOT NULL CHECK(email LIKE '%_@__%.__%'))""")
        with pytest.raises(sqlite3.IntegrityError):
            db.execute("INSERT INTO users (email) VALUES ('invalid')")

    def test_index_used_for_lookup(self, db):
        db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT)")
        db.execute("CREATE INDEX idx_users_email ON users(email)")
        plan = db.execute("EXPLAIN QUERY PLAN SELECT * FROM users WHERE email = ?", ('test@example.com',)).fetchone()
        assert 'USING INDEX' in plan[3]

Step 2: Implement Schema to Pass Tests

# src/database/schema.py
SCHEMA_SQL = """
CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    email TEXT UNIQUE NOT NULL CHECK(email LIKE '%_@__%.__%'),
    name TEXT NOT NULL,
    created_at TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
"""

def init_schema(conn):
    """Initialize database schema."""
    conn.executescript(SCHEMA_SQL)
    conn.commit()

Step 3: Run Tests and Verify

# Run schema tests
pytest tests/test_schema.py -v

# Run with coverage
pytest tests/test_schema.py --cov=src/database --cov-report=term-missing

Step 4: Test Migrations

# tests/test_migrations.py
def test_migration_adds_column(db):
    """Migration should add new column without data loss."""
    # Setup: create old schema with data
    db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT)")
    db.execute("INSERT INTO users (email) VALUES ('test@example.com')")

    # Run migration
    db.execute("ALTER TABLE users ADD COLUMN name TEXT DEFAULT 'Unknown'")

    # Verify: data preserved, new column exists
    row = db.execute("SELECT id, email, name FROM users").fetchone()
    assert row == (1, 'test@example.com', 'Unknown')

8. Performance Patterns

8.1 Indexing Strategies

Good: Composite index with correct column order

-- Query: WHERE user_id = ? AND created_at > ? ORDER BY created_at DESC
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at DESC);

Bad: Wrong column order wastes index

-- Range column first prevents using equality match efficiently
CREATE INDEX idx_orders_wrong ON orders(created_at, user_id);

8.2 Query Optimization

Good: Use covering index to avoid table lookup

-- Include all needed columns in index
CREATE INDEX idx_users_email_cover ON users(email, name, status);
-- Query only touches index, never reads table
SELECT name, status FROM users WHERE email = ?;

**Bad: SELECT * with large rows**

-- Forces table lookup even with index
SELECT * FROM users WHERE email = ?;

8.3 Connection Pooling

Good: Reuse connections with pool

from contextlib import contextmanager
import threading

class ConnectionPool:
    def __init__(self, db_path, max_connections=5):
        self._pool, self._lock = [], threading.Lock()
        self._db_path, self._max = db_path, max_connections

    @contextmanager
    def get_connection(self):
        conn = self._acquire()
        try:
            yield conn
        finally:
            self._release(conn)

Bad: Create new connection per query

def get_user(email):
    conn = sqlite3.connect('app.db')  # Expensive!
    result = conn.execute("SELECT * FROM users WHERE email = ?", (email,)).fetchone()
    conn.close()
    return result

8.4 Denormalization Tradeoffs

Good: Store computed values for read-heavy patterns

CREATE TABLE orders (
    id INTEGER PRIMARY KEY,
    item_count INTEGER NOT NULL DEFAULT 0,  -- Denormalized
    total_amount REAL NOT NULL DEFAULT 0    -- Denormalized
);
-- Use triggers to maintain denormalized values

Bad: Calculate aggregates on every read

SELECT o.id, COUNT(oi.id), SUM(oi.price * oi.quantity)
FROM orders o JOIN order_items oi ON oi.order_id = o.id GROUP BY o.id;

8.5 Partitioning Strategies

Good: Partition large tables by time

CREATE TABLE events_2024 (id INTEGER PRIMARY KEY, event_type TEXT, created_at TEXT CHECK(created_at LIKE '2024%'));
CREATE TABLE events_2025 (id INTEGER PRIMARY KEY, event_type TEXT, created_at TEXT CHECK(created_at LIKE '2025%'));
CREATE VIEW events AS SELECT * FROM events_2024 UNION ALL SELECT * FROM events_2025;

Bad: Single table with millions of rows (10M+ causes full table scans)


9. Common Mistakes & Anti-Patterns

MistakeBadGood
Over-normalizationSeparate tables for first_name, last_nameStore directly in users table
Missing FKuser_id INTEGER (no FK)user_id INTEGER REFERENCES users(id)
Wrong index orderINDEX(created_at, user_id) for WHERE user_id=? AND created_at>?INDEX(user_id, created_at)
CSV in columntags TEXT -- "a,b,c"Junction table with proper FK

10. Pre-Implementation Checklist

Phase 1: Before Writing Code

  • Query patterns identified and documented
  • Performance requirements defined (latency, throughput)
  • Data volume estimates calculated
  • Test fixtures designed for schema validation
  • Migration strategy planned (if modifying existing schema)
  • Reference files read (references/advanced-patterns.md, references/security-examples.md)

Phase 2: During Implementation

  • All tables have PRIMARY KEY
  • Foreign keys defined for all relationships
  • Appropriate ON DELETE actions (CASCADE, RESTRICT, SET NULL)
  • CHECK constraints for data validation
  • UNIQUE constraints where needed
  • NOT NULL for required fields
  • Indexes created for all foreign keys
  • Composite indexes with correct column order (equality before range)
  • FTS5 tables with sync triggers if needed
  • Tests written and passing for constraints

Phase 3: Before Committing

  • pytest tests/test_schema.py -v passes
  • EXPLAIN QUERY PLAN verified for critical queries
  • No redundant indexes
  • Migrations tested with rollback
  • No data loss in migrations
  • Performance benchmarks meet requirements
  • Schema version tracked

11. Summary

Your goal is to create database schemas that are:

  • Normalized: Eliminate redundancy while allowing strategic denormalization
  • Performant: Proper indexing, covering indexes, efficient query patterns
  • Maintainable: Clear naming, documented relationships, migration-friendly
  • Secure: Constraints for validation, foreign keys for integrity

You understand that schema design requires balancing:

  1. Normalization vs. query performance
  2. Indexing benefits vs. write overhead
  3. Flexibility vs. constraints
  4. Current needs vs. future evolution

Design Reminder: Start with 3NF normalization, add indexes based on actual query patterns, and use EXPLAIN to verify your assumptions. When in doubt, consult references/advanced-patterns.md for complex relationship patterns.

平台分布

Antigravity

27.3%
按下载量换算1,335

Claude Code

23.34%
按下载量换算1,141

Codex

15.3%
按下载量换算748

Gemini CLI

12.68%
按下载量换算620

OpenCode

6.91%
按下载量换算338

Cursor

3.56%
按下载量换算174

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills