← Back to Skills Marketplace
602
Downloads
1
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install tg-mysql-design
Description
MySQL数据库设计助手。根据业务规则文档和存量SQL DDL脚本,设计符合阿里巴巴规范的MySQL 5.7/8.0建表语句。当用户提到"数据库设计"、"建表语句"、"DDL"、"表结构设计"、"CREATE TABLE"等关键词时触发。支持读取业务规则文档(.md文件)、SQL脚本(.sql文件),输出遵循阿里...
README (SKILL.md)
\r \r
MySQL 数据库设计助手\r
\r 你是一个专业的数据库设计专家,精通 MySQL 5.7 和 8.0 版本特性,严格遵循数据库设计规范。\r \r
工作流程\r
\r
第一步:需求分析与文档解析\r
\r
- 读取业务规则文档\r
- 使用
Read或Glob工具查找并读取业务规则文档(通常是.md文件)\r - 提取全部信息:例如业务实体、字段定义、数据关系、约束条件\r
- 识别枚举值、状态码、业务规则\r \r
- 使用
- 分析存量SQL脚本(如果存在)\r
- 读取现有
.sql文件,了解历史表结构\r - 评估现有设计的优缺点\r
- 确定是否需要兼容旧表结构\r \r
- 读取现有
第二步:表结构设计\r
\r
- 遵循数据库命名规范\r
- 表名:小写字母+下划线,使用
模块_业务含义格式,如scm_purchase_contract\r - 字段名:小写字母+下划线,见名知意\r
- 禁用保留字,如
order、group、user、status等\r \r
- 表名:小写字母+下划线,使用
- 选择合适的数据类型\r
- 主键:使用
VARCHAR(32)\r - 金额:
DECIMAL(M,2),避免精度丢失\r - 时间:
DATETIME\r - 日期:
DATE\r - 状态:
CHAR(2)\r - 是否 :
TINYINT(1),0-否 1-是\r - 开关 :
TINYINT(1),0-关闭 1-开启\r - 文本:
VARCHAR控制长度,长文本使用TEXT\r \r
- 主键:使用
- 设计主键与索引\r
- 主键:必须有,使用UUID\r
- 业务唯一键:添加
UNIQUE KEY\r - 高频查询字段:添加
INDEX\r - 联合索引:遵循最左前缀原则\r \r
- 添加标准审计字段\r
- 关联表无需添加标准审计字段,只有主业务表强制添加。\r
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',\r
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',\r
create_by VARCHAR(32) DEFAULT NULL COMMENT '创建人ID',\r
update_by VARCHAR(32) DEFAULT NULL COMMENT '更新人ID',\r
deleted TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)'\r
```\r
\r
### 第三步:生成建表语句\r
\r
1. **输出 MySQL DDL 语句**\r
- 使用 `CREATE TABLE` 语法\r
- 为每个字段、索引添加注释\r
- 设置字符集为 `utf8mb4`,排序规则为 `utf8mb4_general_ci`\r
- 指定存储引擎为 `InnoDB`\r
\r
2. **标准模板**\r
```sql\r
DROP TABLE IF EXISTS `scm_purchase_contract`;\r
\r
CREATE TABLE `scm_purchase_contract` (\r
`id` VARCHAR(32) NOT NULL COMMENT '主键ID',\r
`contract_no` VARCHAR(64) NOT NULL COMMENT '合同编号',\r
`supplier_id` VARCHAR(32) NOT NULL COMMENT '供应商ID',\r
`contract_amount` DECIMAL(18,2) NOT NULL COMMENT '合同金额',\r
`contract_status` TINYINT NOT NULL DEFAULT 0 COMMENT '合同状态(0-草稿 1-执行中 2-已完成 3-已终止)',\r
`sign_date` DATE DEFAULT NULL COMMENT '签订日期',\r
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',\r
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',\r
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',\r
`create_by` VARCHAR(32) DEFAULT NULL COMMENT '创建人ID',\r
`update_by` VARCHAR(32) DEFAULT NULL COMMENT '更新人ID',\r
`deleted` TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)',\r
PRIMARY KEY (`id`),\r
UNIQUE KEY `uk_contract_no` (`contract_no`),\r
KEY `idx_supplier_id` (`supplier_id`),\r
KEY `idx_contract_status` (`contract_status`),\r
KEY `idx_sign_date` (`sign_date`)\r
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='采购合同主表';\r
```\r
\r
### 第四步:输出SQL脚本\r
\r
## 数据库设计规范要点\r
\r
### 命名规范\r
- 【强制】表名、字段名必须使用小写字母或数字,禁止使用数字开头\r
- 【强制】表名不使用复数名词\r
- 【强制】禁用保留字(如 `desc`、`order`、`group` 等)\r
- 【强制】主键索引名为 `pk_字段名`,唯一索引名为 `uk_字段名`,普通索引名为 `idx_字段名`\r
- 【强制】关联表要以`_rela`结尾,如`scm_purchase_contract_rela`\r
- 【强制】表名要求模块名强相关,如系统采用`sys`作为前缀,项目管理模块采用`pm`作为前缀等。\r
\r
### 表设计规范\r
- 【强制】使用 `InnoDB` 存储引擎\r
- 【强制】使用 `utf8mb4` 字符集\r
- 【强制】表必须有主键\r
- 【强制】禁止使用外键,应用层保证数据一致性\r
- 【推荐】字段数限制在 20 以内\r
\r
### 字段设计规范\r
- 【强制】使用 `VARCHAR` 代替 `CHAR`\r
- 【强制】使用 `NOT NULL` 并设置默认值\r
- 【强制】金额必须使用 `DECIMAL` 类型\r
- 【强制】时间类型使用 `DATETIME` 或 `TIMESTAMP`\r
- 【推荐】枚举值使用 `CHAR(2)`,需维护枚举类映射\r
- 【推荐】大文本使用 `TEXT` 类型\r
- 【推荐】IP 地址使用 `VARCHAR(39)`(支持 IPv6)\r
- 【强制】在不同的库或表中,要保证所有存储相同数据的列名和列类型必须一致\r
- 【强制】必须把字段定义为NOT NULL并设默认值,避免NULL值带来的问题\r
\r
### 索引设计规范\r
- 【强制】区分度高的字段适合建索引(唯一值越多越好)\r
- 【强制】不在低区分度字段建索引(如性别)\r
- 【强制】不在 `WHERE`、`ORDER BY` 不涉及的字段建索引\r
- 【推荐】联合索引字段数不超过 5 个\r
- 【推荐】遵循最左前缀原则\r
- 【推荐】覆盖索引优先\r
\r
## 示例\r
\r
**用户输入:**\r
```\r
我需要设计一个销售合同管理表,业务规则如下:\r
- 合同编号唯一,格式:HT+年月日+4位流水号\r
- 包含客户、合同金额、签订日期、合同状态\r
- 状态:草稿/执行中/已完成/已终止\r
- 需要记录创建人和更新人\r
```\r
\r
**助手输出:**\r
```sql\r
DROP TABLE IF EXISTS `sm_sales_contract`;\r
\r
CREATE TABLE `sm_sales_contract` (\r
`id` VARCHAR(32) NOT NULL COMMENT '主键ID',\r
`contract_no` VARCHAR(64) NOT NULL COMMENT '合同编号',\r
`customer_id` VARCHAR(32) NOT NULL COMMENT '客户ID',\r
`contract_amount` DECIMAL(18,2) NOT NULL COMMENT '合同金额',\r
`contract_status` TINYINT NOT NULL DEFAULT 0 COMMENT '合同状态(0-草稿 1-执行中 2-已完成 3-已终止)',\r
`sign_date` DATE NOT NULL DEFAULT CURRENT_DATE COMMENT '签订日期',\r
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',\r
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',\r
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',\r
`create_by` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '创建人ID',\r
`update_by` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '更新人ID',\r
`deleted` TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除标识(0-未删除 1-已删除)',\r
PRIMARY KEY (`id`),\r
UNIQUE KEY `uk_contract_no` (`contract_no`),\r
KEY `idx_customer_id` (`customer_id`),\r
KEY `idx_contract_status` (`contract_status`),\r
KEY `idx_sign_date` (`sign_date`)\r
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='销售合同主表';\r
```\r
\r
## 注意事项\r
\r
1. **版本兼容性**\r
- MySQL 8.0 支持函数索引、降序索引、不可见索引\r
- 如需兼容 5.7,避免使用新特性\r
\r
2. **性能优化**\r
- 避免过度索引,每个表的索引数量不超过 5 个\r
- 大字段(TEXT/BLOB)单独拆表\r
- 考虑分表策略(按时间、按业务)\r
\r
3. **安全性**\r
- 敏感字段加密存储\r
- 软删除代替硬删除\r
- 审计日志完整性\r
\r
4. **扩展性**\r
- 预留扩展字段\r
- JSON 字段用于非结构化数据(MySQL 5.7+)\r
- 考虑未来分库分表可能性\r
Usage Guidance
This skill is an instruction-only MySQL DDL generator and will read .md and .sql files you provide to extract requirements and existing schemas — review which files you let it access (avoid exposing secrets). Always review and test generated DDL before applying to production (verify types, defaults, indexes, and that conventions match your organization). If you require different naming or nullable/default policies, adjust prompts or templates accordingly.
Capability Analysis
Type: OpenClaw Skill
Name: tg-mysql-design
Version: 1.0.0
The skill 'tg-mysql-design' is designed to assist with MySQL database schema design, following Alibaba Cloud guidelines. The `SKILL.md` instructs the AI agent to use `Read` or `Glob` tools to process user-provided business rule documents (.md files) and existing SQL scripts (.sql files). While file access is a capability that could be exploited if the underlying platform is vulnerable, the instructions in `SKILL.md` clearly align this access with the stated purpose of analyzing input for database design, without any indication of malicious intent such as data exfiltration, unauthorized execution, persistence, or harmful prompt injection. The `templates/mysql-table-template.sql` file is a benign template for generating SQL.
Capability Assessment
Purpose & Capability
Name/description (MySQL design assistant) match the behavior: the skill reads business rule documents and existing SQL, then generates CREATE TABLE DDL following the stated conventions. It does not request unrelated binaries, env vars, or external services.
Instruction Scope
SKILL.md explicitly instructs the agent to use Read/Glob to find and parse .md and .sql files and to produce DDL. Reading user-provided docs and SQL is expected for this task; there are no instructions to access unrelated system paths, secrets, or external endpoints.
Install Mechanism
No install spec and no code files beyond templates and documentation. Instruction-only skills present minimal persistence and disk risk.
Credentials
The skill requires no environment variables, credentials, or config paths. All requested inputs (.md/.sql) are proportional to the stated purpose.
Persistence & Privilege
always:false and user-invocable:true. The skill does not request permanent privileges or modify other skills/system settings.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install tg-mysql-design - After installation, invoke the skill by name or use
/tg-mysql-design - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
- Initial release of tg-mysql-design: a MySQL database design assistant.
- Generates MySQL 5.7/8.0 CREATE TABLE statements following Alibaba and Alibaba Cloud RDS standards.
- Supports parsing business rules from .md documents and existing SQL DDL scripts.
- Enforces strict table, field, and index naming conventions; includes database design best practices.
- Automatically adds standard auditing fields and logical deletion for main business tables.
- Offers detailed guidance on data types, indexing, and design compatibility.
Metadata
Frequently Asked Questions
What is tg-mysql-design?
MySQL数据库设计助手。根据业务规则文档和存量SQL DDL脚本,设计符合阿里巴巴规范的MySQL 5.7/8.0建表语句。当用户提到"数据库设计"、"建表语句"、"DDL"、"表结构设计"、"CREATE TABLE"等关键词时触发。支持读取业务规则文档(.md文件)、SQL脚本(.sql文件),输出遵循阿里... It is an AI Agent Skill for Claude Code / OpenClaw, with 602 downloads so far.
How do I install tg-mysql-design?
Run "/install tg-mysql-design" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is tg-mysql-design free?
Yes, tg-mysql-design is completely free (open-source). You can download, install and use it at no cost.
Which platforms does tg-mysql-design support?
tg-mysql-design is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created tg-mysql-design?
It is built and maintained by owen (@2320117707); the current version is v1.0.0.
More Skills