Designs production-ready database schemas with tables, fields, indexes, ER diagrams, Markdown docs, SQL scripts, and DrawDB/DBML files for MySQL, PostgreSQL, SQL Server.
npx claudepluginhub shining319/claude-code-single-person-workflow --plugin product-workflow-agentsThis skill uses the workspace's default tool permissions.
Design complete, production-ready database schemas based on user requirements. Generate comprehensive documentation, SQL scripts, and visual ER diagram files compatible with DrawDB.
Designs complete database schemas with tables, fields, indexes, ER diagrams for MySQL, PostgreSQL, SQL Server. Generates Markdown docs, SQL scripts, DrawDB JSON/DBML files.
Generates ERDs, Mermaid/PlantUML diagrams, schema docs, and insights from SQL dumps, ORM models (Prisma, SQLAlchemy, TypeORM), migrations, or live DBs.
Designs normalized (3NF) relational database schemas with indexes, constraints, naming conventions, and documentation from functional requirements. Guides entity extraction, relationships, and ERD generation.
Share bugs, ideas, or general feedback.
Design complete, production-ready database schemas based on user requirements. Generate comprehensive documentation, SQL scripts, and visual ER diagram files compatible with DrawDB.
Before starting any design, always read references/design-principles.md to understand:
Gather information about the database design:
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:
Based on the design requirements, load appropriate references:
references/design-principles.md for core design rulesreferences/drawdb-formats.md for JSON/DBML specificationsreferences/design-examples.md for similar system designsCreate complete table structures following these guidelines:
For each table:
✅ Add default system fields (unless user specifies otherwise):
id BIGINT AUTO_INCREMENT PRIMARY KEYcreated_at DATETIME DEFAULT CURRENT_TIMESTAMPupdated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPis_deleted TINYINT(1) DEFAULT 0✅ Design business fields with realistic sizes:
references/design-principles.md for complete size standards✅ Add appropriate constraints:
✅ Add COMMENT to every table and field (in Chinese)
✅ Do NOT create physical FOREIGN KEY constraints
For each table, analyze and create indexes for:
xxx_id foreign key fieldsIndex naming conventions:
idx_field_name or idx_field1_field2uk_field_nameIndex limits:
Identify logical relationships between tables:
One-to-Many (1:N): Most common
user_id in order tableOne-to-One (1:1): For table splitting
user_id UNIQUE in user_profile tableMany-to-Many (N:N): Requires junction table
Create all required output files:
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
Create executable SQL script with:
-- Database: project_name
-- Generated: YYYY-MM-DD
-- Drop tables if exists (in reverse dependency order)
DROP TABLE IF EXISTS `table3`;
DROP TABLE IF EXISTS `table2`;
DROP TABLE IF EXISTS `table1`;
-- Create tables (in dependency order)
CREATE TABLE `table1` (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Comment',
...
PRIMARY KEY (`id`),
UNIQUE KEY `uk_field` (`field`),
KEY `idx_field` (`field`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Table comment';
CREATE TABLE `table2` (
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Table comment';
Generate DrawDB-compatible JSON file following references/drawdb-formats.md:
Critical Format Requirements:
"_KV5MtPf2m4sI7Inu8pat")"B8rPRTDtOv9oD2Gp4bhWL")"VARCHAR(100)", not separate type and size)["email"] not [1])ID Generation:
import random
import string
def generate_id():
chars = string.ascii_letters + string.digits + '_-'
return ''.join(random.choice(chars) for _ in range(21))
Layout Strategy:
x = (index % 3) * 450 + 50, y = floor(index / 3) * 400 + 50["#6360f7", "#bc49c4", "#ffe159", "#89e667", "#ff9159", "#59d9ff", "#ff5959", "#a0a0a0"]Relationship Generation:
xxx_id foreign key fieldsStructure:
{
"tables": [
{
"id": "random_string",
"name": "table_name",
"comment": "表注释",
"color": "#6360f7",
"fields": [
{
"id": "random_string",
"name": "id",
"type": "BIGINT",
"default": "",
"check": "",
"primary": true,
"unique": true,
"notNull": true,
"increment": true,
"comment": "主键ID"
}
],
"indices": [
{
"id": 0,
"fields": ["field_name"],
"name": "idx_field_name",
"unique": false
}
],
"x": 50.0,
"y": 50.0
}
],
"relationships": [
{
"name": "",
"startTableId": "random_string",
"endTableId": "random_string",
"endFieldId": "random_string",
"startFieldId": "random_string",
"id": "random_string",
"updateConstraint": "No action",
"deleteConstraint": "No action",
"cardinality": "many_to_one"
}
],
"notes": [],
"subjectAreas": [],
"database": "generic",
"types": [],
"title": "Project Database"
}
Generate DBML file following references/drawdb-formats.md:
Key points:
bigint, varchar(50), datetime[pk, increment, not null, unique, note: '注释']indexes { } blockRef blocks> (many-to-one), - (one-to-one)Structure:
Table table_name [headercolor: #6360f7] {
id bigint [pk, increment, not null, unique, note: 'Comment']
field varchar(100) [not null, note: 'Comment']
indexes {
field [unique, name: 'uk_field']
}
Note: 'Table comment'
}
Ref fk_name {
table1.field > table2.id [delete: no action, update: no action]
}
Recommended Approach (Following Claude Code Official Standards):
Save all database design files to outputs/<project-name>/database/:
outputs/
└── <project-name>/ # Project name (e.g., e-commerce-system)
└── database/
├── schema-design.md # Comprehensive design document
├── schema.sql # Executable SQL script
├── drawdb-schema.json # DrawDB JSON format
└── drawdb-schema.dbml # DrawDB DBML format
Example:
outputs/
├── e-commerce-system/
│ └── database/
│ ├── schema-design.md
│ ├── schema.sql
│ ├── drawdb-schema.json
│ └── drawdb-schema.dbml
└── task-management-app/
└── database/
├── schema-design.md
└── schema.sql
Alternative Approach (Traditional Project Structure):
If your project has an existing directory structure, you can also use:
project-root/
└── database/
├── schema-design.md
├── schema.sql
├── drawdb-schema.json
└── drawdb-schema.dbml
Required Outputs (4 files):
schema-design.md - Comprehensive database design document (Chinese)schema.sql - Executable SQL scriptdrawdb-schema.json - DrawDB JSON formatdrawdb-schema.dbml - DrawDB DBML formatOptional Outputs:
er-diagram.png - ER diagram visualization (if tools available)index-strategy.md - Index strategy documentationuser-authentication-schema.sqlschema-v1.0.sql or schema-2024-12-10.sqle-commerce-database-schema.sqlAfter generating all files, provide a summary with:
Only create minimal structure:
CREATE TABLE `table_name` (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
/* business fields only */
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Table comment';
Adapt SQL syntax accordingly:
PostgreSQL:
SERIAL or BIGSERIAL instead of AUTO_INCREMENTTIMESTAMP instead of DATETIMESQL Server:
IDENTITY(1,1) instead of AUTO_INCREMENTDATETIME2 instead of DATETIMENVARCHAR for Unicode supportOracle:
SEQUENCE for auto-incrementVARCHAR2 instead of VARCHARDATE or TIMESTAMP for time fieldsApply intelligent inference:
references/design-examples.mdBefore finalizing, verify:
User says: "设计一个电商系统的数据库,包括用户、商品、订单功能" → Read design-principles.md and design-examples.md → Design: user_info, product_info, order_info, order_detail tables → Generate all 4 output files
User says: "Design a blog database" → Infer: user, article, comment, tag, article_tag tables → Follow standard design principles → Generate all outputs
User says: "Create a user table for PostgreSQL" → Single table design → Adapt SQL syntax for PostgreSQL → Include in all output formats
references/design-principles.md - Core design rules and standardsreferences/drawdb-formats.md - JSON and DBML format specificationsreferences/design-examples.md - Real-world design examples