database-designer
from shining319/claude-code-single-person-workflow
A curated collection of Claude Code plugins designed specifically for single-person product development workflows. From writing documentation to designing databases, from product management to UI/UX design and solution architecture - everything you need in one marketplace.
npx skills add https://github.com/shining319/claude-code-single-person-workflow --skill database-designerSKILL.md
Database Designer
Design complete, production-ready database schemas based on user requirements. Generate comprehensive documentation, SQL scripts, and visual ER diagram files compatible with DrawDB.
Core Design Principles
Before starting any design, always read references/design-principles.md to understand:
- No physical foreign keys (logical relationships only)
- Realistic field sizes based on actual usage
- Minimal, strategic index design
- Mandatory comments on all tables and fields
- Default system fields (id, timestamps, soft delete)
- snake_case naming conventions
Workflow
Step 1: Understand Requirements
Gather information about the database design:
- Database type: MySQL 8.0 (default), PostgreSQL, SQL Server, etc.
- Business domain: E-commerce, blog, CRM, ERP, etc.
- Core entities: What are the main tables needed?
- Key features: What functionality should the database support?
- Special requirements: Any specific constraints or preferences?
If the user provides minimal information, intelligently infer missing details based on common business scenarios and best practices documented in references/design-examples.md.
Key inference scenarios:
- User says "design a user table" → Infer: username, password, email, phone, status
- User says "e-commerce system" → Infer: user, product, order, order_detail tables
- User says "blog system" → Infer: user, article, comment, tag, article_tag tables
Step 2: Load Reference Documentation
Based on the design requirements, load appropriate references:
- Always load:
references/design-principles.mdfor core design rules - For format generation:
references/drawdb-formats.mdfor JSON/DBML specifications - For examples:
references/design-examples.mdfor similar system designs
Step 3: Design Database Schema
Create complete table structures following these guidelines:
Table Design Checklist
For each table:
-
✅ Add default system fields (unless user specifies otherwise):
idBIGINT AUTO_INCREMENT PRIMARY KEYcreated_atDATETIME DEFAULT CURRENT_TIMESTAMPupdated_atDATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPis_deletedTINYINT(1) DEFAULT 0
-
✅ Design business fields with realistic sizes:
- username: VARCHAR(50)
- email: VARCHAR(100)
- phone: VARCHAR(20)
- title: VARCHAR(200)
- description: TEXT
- See
references/design-principles.mdfor complete size standards
-
✅ Add appropriate constraints:
- NOT NULL for required fields
- DEFAULT values for optional fields
- UNIQUE for fields requiring uniqueness (but not as foreign keys)
-
✅ Add COMMENT to every table and field (in Chinese)
-
✅ Do NOT create physical FOREIGN KEY constraints
Index Design Strategy
For each table, analyze and create indexes for:
- WHERE clause fields: Fields frequently used in filtering
- JOIN fields: All
xxx_idforeign key fields - ORDER BY / GROUP BY fields: Sorting and grouping fields
- Unique constraints: email, phone, order_no, etc. → UNIQUE indexes
Index naming conventions:
- Ordinary index:
idx_field_nameoridx_field1_field2 - Unique index:
uk_field_name
Index limits:
- Maximum 5 indexes per table (unless user requests more)
- Only create indexes that directly support business queries
Relationship Design
Identify logical relationships between tables:
-
One-to-Many (1:N): Most common
- Example: user (1) → order (N)
- Implementation: Add
user_idin order table - DrawDB: many-to-one relationship
-
One-to-One (1:1): For table splitting
- Example: user (1) → user_profile (1)
- Implementation: Add
user_id UNIQUEin user_profile table - DrawDB: one-to-one relationship
-
Many-to-Many (N:N): Requires junction table
- Example: article (N) ↔ tag (N)
- Implementation: Create article_tag junction table with article_id + tag_id
- DrawDB: Two many-to-one relationships
Step 4: Generate Outputs
Create all required output files:
4.1 Comprehensive Design Document (Markdown)
Create a single, well-structured Markdown file containing:
Structure:
# [Project Name] 数据库设计文档
## 1. 数据库概览
- 数据库类型
- 字符集
- 核心表数量
- 主要功能模块
## 2. 表结构设计
### 2.1 [Table Name]
**表名**: table_name
**说明**: Table description
**字段列表**:
| 字段名 | 类型 | 允许空 | 默认值 | 说明 |
|--------|------|--------|--------|------|
| id | BIGINT | NO | | Primary key |
| ... | ... | ... | ... | ... |
**索引列表**:
| 索引名 | 类型 | 字段 |
|--------|------|------|
| uk_email | UNIQUE | email |
| idx_username | INDEX | username |
### 2.2 [Next Table]
...
## 3. 表关系说明
- table1 → table2 (1:N): Description
- table3 ↔ table4 (N:N): Description via junction table
## 4. 索引策略说明
Explain the rationale behind index design decisions
4.2 SQL Script
Create executable SQL script with:
-- Database: project_name
-- Generated: YYYY-MM-DD
-- Drop tables if exists (in reverse dependency order)
DROP TABLE IF
...