data-model-creation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

When to use this skill

何时使用该技能

This is an OPTIONAL advanced modeling tool for complex database design. Most simple table creation should use
relational-database-tool
directly with SQL statements.
ONLY use this skill when you specifically need:
  • Complex multi-table relationships with automatic foreign key management
  • Visual ER diagram generation for documentation
  • Automated field type mapping and constraint generation
  • Enterprise-level data model documentation
For most cases, use
rules/relational-database-tool/rule.md
instead:
  • Simple table creation with CREATE TABLE statements
  • Basic CRUD operations
  • Schema modifications with ALTER TABLE
  • Direct SQL execution without Mermaid modeling
Do NOT use for:
  • Querying or manipulating existing data (use database skills)
  • NoSQL database design (use NoSQL skills)
  • Frontend data structures (use appropriate frontend skills)

这是一个可选的高级建模工具,用于复杂的数据库设计。大多数简单的表创建应直接使用
relational-database-tool
结合SQL语句。
仅在明确需要以下功能时使用该技能:
  • 带有自动外键管理的复杂多表关系
  • 用于文档的可视化ER图生成
  • 自动化字段类型映射和约束生成
  • 企业级数据模型文档
大多数情况下,请使用
rules/relational-database-tool/rule.md
替代:
  • 使用CREATE TABLE语句创建简单表
  • 基础CRUD操作
  • 使用ALTER TABLE修改Schema
  • 无需Mermaid建模的直接SQL执行
请勿用于:
  • 查询或操作现有数据(使用数据库相关技能)
  • NoSQL数据库设计(使用NoSQL相关技能)
  • 前端数据结构(使用相应的前端技能)

How to use this skill (for a coding agent)

如何使用该技能(适用于编码Agent)

⚠️ NOTE: This is OPTIONAL. For simple tasks, skip this and use
relational-database-tool
directly.
When you do use this advanced modeling approach:
  1. Optional modeling workflow (only when complexity justifies it)
    • Business analysis phase: Analyze user requirements, identify core entities and relationships
    • Mermaid modeling phase: Create mermaid classDiagram following generation rules
    • Model validation phase: Check completeness, consistency, and correctness
  2. Apply generation rules strictly (when using this tool)
    • Use correct type mappings (string, number, boolean, x-enum, etc.)
    • Convert Chinese to English naming (PascalCase for classes, camelCase for fields)
    • Define required(), unique(), display_field() functions when needed
    • Use proper relationship notation with field names
  3. Use tools correctly (only when you choose this approach)
    • Call data model creation tools only for complex multi-entity business requirements
    • Use
      mermaidDiagram
      parameter with complete mermaid classDiagram code
    • Set
      publish
      to false initially, create then publish separately
    • Choose appropriate
      updateMode
      for new or existing models

⚠️ 注意:这是可选工具。对于简单任务,请跳过此工具,直接使用
relational-database-tool
当你确实需要使用这种高级建模方法时:
  1. 可选建模工作流(仅在复杂度较高时使用)
    • 业务分析阶段:分析用户需求,识别核心实体和关系
    • Mermaid建模阶段:按照生成规则创建mermaid classDiagram
    • 模型验证阶段:检查完整性、一致性和正确性
  2. 严格应用生成规则(使用该工具时)
    • 使用正确的类型映射(string、number、boolean、x-enum等)
    • 将中文名称转换为英文命名(类名使用PascalCase,字段名使用camelCase)
    • 必要时定义required()、unique()、display_field()函数
    • 使用带有字段名的正确关系表示法
  3. 正确使用工具(仅在选择此方法时)
    • 仅针对复杂多实体业务需求调用数据模型创建工具
    • 使用
      mermaidDiagram
      参数传入完整的mermaid classDiagram代码
    • 初始时将
      publish
      设置为false,先创建再发布
    • 为新模型或现有模型选择合适的
      updateMode

Quick Decision Guide

快速决策指南

Most Database Tasks →
rules/relational-database-tool/rule.md
  • ✅ Simple table creation
  • ✅ Data queries and modifications
  • ✅ Schema changes
  • ✅ Direct SQL execution
Complex Modeling Only → This rule (
rules/data-model-creation/rule.md
)
  • 🎯 Multi-entity relationship modeling
  • 🎯 Automated foreign key management
  • 🎯 Visual ER diagram generation
  • 🎯 Enterprise documentation

大多数数据库任务 → 使用
rules/relational-database-tool/rule.md
  • ✅ 创建简单表
  • ✅ 数据查询和修改
  • ✅ Schema修改
  • ✅ 直接执行SQL
仅用于复杂建模 → 本规则(
rules/data-model-creation/rule.md
  • 🎯 多实体关系建模
  • 🎯 自动化外键管理
  • 🎯 可视化ER图生成
  • 🎯 企业级文档

Data Model AI Modeling Professional Rules

数据模型AI建模专业规则

⚠️ IMPORTANT: Simplified Workflow Recommendation

⚠️ 重要:简化工作流建议

For most database table creation tasks, use
rules/relational-database-tool/rule.md
directly:
  • Simple table creation:
    CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255))
  • Schema modifications:
    ALTER TABLE users ADD COLUMN email VARCHAR(255)
  • Data operations:
    INSERT
    ,
    UPDATE
    ,
    SELECT
    ,
    DELETE
Only use this advanced Mermaid modeling approach when:
  • You need automated relationship management
  • Complex multi-table schemas with foreign keys
  • Enterprise documentation requirements
  • Visual ER diagram generation
This rule exists for complex modeling scenarios, but most development should use direct SQL execution.
大多数数据库表创建任务,请直接使用
rules/relational-database-tool/rule.md
  • 创建简单表:
    CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255))
  • 修改Schema:
    ALTER TABLE users ADD COLUMN email VARCHAR(255)
  • 数据操作:
    INSERT
    UPDATE
    SELECT
    DELETE
仅在以下情况使用这种高级Mermaid建模方法:
  • 需要自动化关系管理
  • 带有外键的复杂多表Schema
  • 企业级文档需求
  • 可视化ER图生成
本规则适用于复杂建模场景,但大多数开发应使用直接SQL执行。

AI Modeling Expert Prompt

AI建模专家提示

As an expert in data modeling and a senior architect in software development, you are proficient in Mermaid. Your main task is to provide model structures in mermaid classDiagram format based on user descriptions, following the detailed rules below:
作为数据建模专家和软件开发资深架构师,你精通Mermaid。你的主要任务是根据用户描述,按照以下详细规则提供mermaid classDiagram格式的模型结构:

Generation Rules

生成规则

  1. Type Mapping Priority: When user-described fields match the mapping relationship, prioritize using type as the field type. Mapping relationships are as follows:
    Business Fieldtype
    Textstring
    Numbernumber
    Booleanboolean
    Enumx-enum
    Emailemail
    Phonephone
    URLurl
    Filex-file
    Imagex-image
    Rich Textx-rtf
    Regionx-area-code
    Timetime
    Datedate
    DateTimedatetime
    Objectobject
    Arraystring[]
    Locationx-location
  2. Naming Convention: Convert Chinese descriptions to English naming (except enum values). Use PascalCase for class names, camelCase for field names.
  3. Field Visibility: Use default visibility for fields, do not add "+" or "-".
  4. Array Types: When descriptions include array types, use specific array formats such as string[], number[], x-rtf[], etc.
  5. Chinese Administrative Regions: When involving Chinese administrative regions like "province/city/district", use x-area-code field type.
  6. Required Fields: When descriptions explicitly mention required fields, define a required() parameterless function, return value as string array of required field names, e.g.,
    required() ["name", "age"]
    . By default, fields are not required.
  7. Unique Fields: When descriptions explicitly mention unique fields, define a unique() parameterless function, return value as string array of unique field names, e.g.,
    unique() ["name", "age"]
    . By default, fields are not unique.
  8. Default Values: When descriptions explicitly require field default values, use "= default value" format after field definition, e.g.,
    age: number = 0
    . By default, fields have no default values.
  9. Field Descriptions: For each field definition in user descriptions, use
    <<description>>
    format at the end of the definition line, e.g.,
    name: string <<Name>>
    .
  10. Display Field: Each entity class should have a field for display when being referenced. Usually a human-readable name or unique identifier. Define display_field() parameterless function, return value is a field name representing the main display field, e.g.,
    display_field() "name"
    means the main display field is name. Otherwise, default to the implicit _id of the data model.
  11. Class Notes: After all class definitions are complete, use note to describe class names. First use "%% Class naming" to anchor the area, then provide Chinese table names for each class.
  12. Relationships: When descriptions contain relationships, relationship label LabelText should not use original semantics, but use relationship field names. For example,
    A "n" <-- "1" B: field1
    means A has many-to-one relationship with B, data exists in A's field1 field. Refer to examples for specifics.
  13. Naming: Field names and descriptions in Mermaid should be concise and accurately expressed.
  14. Complexity Control: Unless user requires, control complexity, e.g., number of classes should not exceed 5, control field complexity.
  1. 类型映射优先级:当用户描述的字段与映射关系匹配时,优先使用对应的type作为字段类型。映射关系如下:
    业务字段type
    文本string
    数字number
    布尔值boolean
    枚举x-enum
    邮箱email
    电话phone
    网址url
    文件x-file
    图片x-image
    富文本x-rtf
    地区x-area-code
    时间time
    日期date
    日期时间datetime
    对象object
    数组string[]
    位置x-location
  2. 命名规范:将中文描述转换为英文命名(枚举值除外)。类名使用PascalCase,字段名使用camelCase。
  3. 字段可见性:使用字段的默认可见性,不要添加"+"或"-"。
  4. 数组类型:当描述包含数组类型时,使用特定的数组格式,如string[]、number[]、x-rtf[]等。
  5. 中国行政区划:当涉及“省/市/区”等中国行政区划时,使用x-area-code字段类型。
  6. 必填字段:当描述明确提到必填字段时,定义一个无参数的required()函数,返回值为必填字段名称的字符串数组,例如
    required() ["name", "age"]
    。默认情况下,字段为非必填。
  7. 唯一字段:当描述明确提到唯一字段时,定义一个无参数的unique()函数,返回值为唯一字段名称的字符串数组,例如
    unique() ["name", "age"]
    。默认情况下,字段为非唯一。
  8. 默认值:当描述明确要求字段默认值时,在字段定义后使用“= 默认值”格式,例如
    age: number = 18 <<Age>>
    。默认情况下,字段没有默认值。
  9. 字段描述:对于用户描述中的每个字段定义,在定义行末尾使用
    <<描述>>
    格式,例如
    name: string <<姓名>>
  10. 显示字段:每个实体类应有一个在被引用时用于显示的字段,通常是易读的名称或唯一标识符。定义display_field()无参数函数,返回值为代表主要显示字段的字段名,例如
    display_field() "name"
    表示主要显示字段为name。否则,默认使用数据模型的隐式_id。
  11. 类注释:在所有类定义完成后,使用note描述类名。首先使用
    %% Class naming
    锚定区域,然后为每个类提供中文表名。
  12. 关系:当描述包含关系时,关系标签LabelText不应使用原始语义,而应使用关系字段名。例如
    A "n" <-- "1" B: field1
    表示A与B存在多对一关系,数据存储在A的field1字段中。具体请参考示例。
  13. 命名:Mermaid中的字段名和描述应简洁准确。
  14. 复杂度控制:除非用户要求,否则控制复杂度,例如类的数量不应超过5个,控制字段复杂度。

Standard Example

标准示例

mermaid
classDiagram
    class Student {
        name: string <<Name>>
        age: number = 18 <<Age>>
        gender: x-enum = "Male" <<Gender>>
        classId: string <<Class ID>>
        identityId: string <<Identity ID>>
        course: Course[] <<Courses>>
        required() ["name"]
        unique() ["name"]
        enum_gender() ["Male", "Female"]
        display_field() "name"
    }
    class Class {
        className: string <<Class Name>>
        display_field() "className"
    }
    class Course {
        name: string <<Course Name>>
        students: Student[] <<Students>>
        display_field() "name"
    }
    class Identity {
        number: string <<ID Number>>
        display_field() "number"
    }

    %% Relationships
    Student "1" --> "1" Identity : studentId
    Student "n" --> "1" Class : student2class
    Student "n" --> "m" Course : course
    Student "n" <-- "m" Course : students
    %% Class naming
    note for Student "Student Model"
    note for Class "Class Model"
    note for Course "Course Model"
    note for Identity "Identity Model"
mermaid
classDiagram
    class Student {
        name: string <<Name>>
        age: number = 18 <<Age>>
        gender: x-enum = "Male" <<Gender>>
        classId: string <<Class ID>>
        identityId: string <<Identity ID>>
        course: Course[] <<Courses>>
        required() ["name"]
        unique() ["name"]
        enum_gender() ["Male", "Female"]
        display_field() "name"
    }
    class Class {
        className: string <<Class Name>>
        display_field() "className"
    }
    class Course {
        name: string <<Course Name>>
        students: Student[] <<Students>>
        display_field() "name"
    }
    class Identity {
        number: string <<ID Number>>
        display_field() "number"
    }

    %% Relationships
    Student "1" --> "1" Identity : studentId
    Student "n" --> "1" Class : student2class
    Student "n" --> "m" Course : course
    Student "n" <-- "m" Course : students
    %% Class naming
    note for Student "Student Model"
    note for Class "Class Model"
    note for Course "Course Model"
    note for Identity "Identity Model"

Data Model Creation Workflow

数据模型创建工作流

1. Business Analysis Phase

1. 业务分析阶段

  • Carefully analyze user's business requirement descriptions
  • Identify core entities and business objects
  • Determine relationships between entities
  • Clarify required fields, unique constraints, and default values
  • 仔细分析用户的业务需求描述
  • 识别核心实体和业务对象
  • 确定实体之间的关系
  • 明确必填字段、唯一约束和默认值

2. Mermaid Modeling Phase

2. Mermaid建模阶段

  • Strictly follow the above generation rules to create mermaid classDiagram
  • Ensure field type mappings are correct
  • Properly handle relationship directions and cardinalities
  • Add complete Chinese descriptions and comments
  • 严格按照上述生成规则创建mermaid classDiagram
  • 确保字段类型映射正确
  • 正确处理关系方向和基数
  • 添加完整的中文描述和注释

3. Model Validation Phase

3. 模型验证阶段

  • Check model completeness and consistency
  • Verify relationship rationality
  • Confirm field constraint correctness
  • Check naming convention compliance
  • 检查模型的完整性和一致性
  • 验证关系的合理性
  • 确认字段约束的正确性
  • 检查命名规范的合规性

MySQL Data Type Support

MySQL数据类型支持

Basic Type Mappings

基础类型映射

  • string
    → VARCHAR/TEXT
  • number
    → INT/BIGINT/DECIMAL
  • boolean
    → BOOLEAN/TINYINT
  • date
    → DATE
  • datetime
    → DATETIME
  • time
    → TIME
  • string
    → VARCHAR/TEXT
  • number
    → INT/BIGINT/DECIMAL
  • boolean
    → BOOLEAN/TINYINT
  • date
    → DATE
  • datetime
    → DATETIME
  • time
    → TIME

Extended Type Mappings

扩展类型映射

  • x-enum
    → ENUM type
  • x-file
    /
    x-image
    → File path storage
  • x-rtf
    → LONGTEXT rich text
  • x-area-code
    → Region code
  • x-location
    → Geographic location coordinates
  • email
    /
    phone
    /
    url
    → VARCHAR with validation
  • x-enum
    → ENUM类型
  • x-file
    /
    x-image
    → 文件路径存储
  • x-rtf
    → LONGTEXT富文本
  • x-area-code
    → 地区编码
  • x-location
    → 地理位置坐标
  • email
    /
    phone
    /
    url
    → 带验证的VARCHAR

Relationship Implementation

关系实现

  • One-to-one: Foreign key constraints
  • One-to-many: Foreign key associations
  • Many-to-many: Intermediate table implementation
  • Self-association: Same table foreign key
  • 一对一:外键约束
  • 一对多:外键关联
  • 多对多:中间表实现
  • 自关联:同表外键

Tool Usage Guidelines

工具使用指南

Tool Call Timing (RARE - Use Sparingly)

工具调用时机(罕见 - 谨慎使用)

  1. Only when user explicitly requests advanced data modeling with Mermaid diagrams
  2. Only for complex enterprise applications with multi-entity relationships
  3. Only when user provides detailed business requirement descriptions requiring automated modeling
  4. Only when you need to update existing data model structure AND want visual ER diagrams
  1. 仅当用户明确要求使用Mermaid图进行高级数据建模时
  2. 仅适用于带有多实体关系的复杂企业应用
  3. 仅当用户提供了需要自动化建模的详细业务需求描述时
  4. 仅当你需要更新现有数据模型结构且需要可视化ER图时

When to SKIP this tool (Most Cases)

何时跳过此工具(大多数情况)

  • Simple table creation → Use
    executeWriteSQL
    with CREATE TABLE
  • Schema changes → Use
    executeWriteSQL
    with ALTER TABLE
  • Basic CRUD → Use appropriate SQL statements directly
  • Data queries → Use
    executeReadOnlySQL
  • 简单表创建 → 使用
    executeWriteSQL
    执行CREATE TABLE
  • Schema修改 → 使用
    executeWriteSQL
    执行ALTER TABLE
  • 基础CRUD → 直接使用相应的SQL语句
  • 数据查询 → 使用
    executeReadOnlySQL

Parameter Usage Guide

参数使用指南

  • mermaidDiagram
    : Complete mermaid classDiagram code
  • publish
    : Whether to publish model immediately (recommend default to false, create then publish)
  • updateMode
    : Create new model or update existing model
  • mermaidDiagram
    :完整的mermaid classDiagram代码
  • publish
    :是否立即发布模型(建议默认设为false,先创建再发布)
  • updateMode
    :创建新模型或更新现有模型

Error Handling Strategy

错误处理策略

  • Syntax errors: Check Mermaid syntax format
  • Field type errors: Verify type mapping relationships
  • Relationship errors: Check relationship directions and cardinalities
  • Naming conflicts: Provide renaming suggestions
  • 语法错误:检查Mermaid语法格式
  • 字段类型错误:验证类型映射关系
  • 关系错误:检查关系方向和基数
  • 命名冲突:提供重命名建议

Best Practices

最佳实践

Model Design Principles

模型设计原则

  1. Single Responsibility: Each entity class is responsible for only one business concept
  2. Minimize Dependencies: Reduce unnecessary relationships
  3. Extensibility: Reserve field space for future expansion
  4. Consistency: Maintain consistency in naming and type usage
  1. 单一职责:每个实体类仅负责一个业务概念
  2. 最小化依赖:减少不必要的关系
  3. 可扩展性:为未来扩展预留字段空间
  4. 一致性:保持命名和类型使用的一致性

Performance Considerations

性能考虑

  1. Index Design: Create indexes for commonly queried fields
  2. Field Length: Reasonably set string field lengths
  3. Relationship Optimization: Avoid excessive many-to-many relationships
  4. Data Sharding: Consider table sharding strategies for large tables
  1. 索引设计:为常用查询字段创建索引
  2. 字段长度:合理设置字符串字段长度
  3. 关系优化:避免过多的多对多关系
  4. 数据分片:对大表考虑分表策略

Security Standards

安全标准

  1. Sensitive Fields: Encrypt storage for sensitive information like passwords
  2. Permission Control: Clarify read/write permissions for fields
  3. Data Validation: Set appropriate field constraints
  4. Audit Logs: Add operation records for important entities
  1. 敏感字段:对密码等敏感信息进行加密存储
  2. 权限控制:明确字段的读写权限
  3. 数据验证:设置适当的字段约束
  4. 审计日志:为重要实体添加操作记录

Common Business Scenario Templates

常见业务场景模板

User Management System

用户管理系统

mermaid
classDiagram
    class User {
        username: string <<Username>>
        email: email <<Email>>
        password: string <<Password>>
        avatar: x-image <<Avatar>>
        status: x-enum = "active" <<Status>>
        required() ["username", "email"]
        unique() ["username", "email"]
        enum_status() ["active", "inactive", "banned"]
        display_field() "username"
    }
mermaid
classDiagram
    class User {
        username: string <<Username>>
        email: email <<Email>>
        password: string <<Password>>
        avatar: x-image <<Avatar>>
        status: x-enum = "active" <<Status>>
        required() ["username", "email"]
        unique() ["username", "email"]
        enum_status() ["active", "inactive", "banned"]
        display_field() "username"
    }

E-commerce System

电商系统

mermaid
classDiagram
    class Product {
        name: string <<Product Name>>
        price: number <<Price>>
        description: x-rtf <<Product Description>>
        images: x-image[] <<Product Images>>
        category: string <<Category>>
        stock: number = 0 <<Stock>>
        required() ["name", "price"]
        display_field() "name"
    }
    class Order {
        orderNo: string <<Order Number>>
        totalAmount: number <<Total Amount>>
        status: x-enum = "pending" <<Order Status>>
        createTime: datetime <<Create Time>>
        required() ["orderNo", "totalAmount"]
        unique() ["orderNo"]
        enum_status() ["pending", "paid", "shipped", "completed", "cancelled"]
        display_field() "orderNo"
    }
mermaid
classDiagram
    class Product {
        name: string <<Product Name>>
        price: number <<Price>>
        description: x-rtf <<Product Description>>
        images: x-image[] <<Product Images>>
        category: string <<Category>>
        stock: number = 0 <<Stock>>
        required() ["name", "price"]
        display_field() "name"
    }
    class Order {
        orderNo: string <<Order Number>>
        totalAmount: number <<Total Amount>>
        status: x-enum = "pending" <<Order Status>>
        createTime: datetime <<Create Time>>
        required() ["orderNo", "totalAmount"]
        unique() ["orderNo"]
        enum_status() ["pending", "paid", "shipped", "completed", "cancelled"]
        display_field() "orderNo"
    }

Content Management System

内容管理系统

mermaid
classDiagram
    class Article {
        title: string <<Title>>
        content: x-rtf <<Content>>
        author: string <<Author>>
        publishTime: datetime <<Publish Time>>
        status: x-enum = "draft" <<Status>>
        tags: string[] <<Tags>>
        required() ["title", "content", "author"]
        enum_status() ["draft", "published", "archived"]
        display_field() "title"
    }
These rules will guide AI Agents to generate high-quality, business-requirement-compliant data models during the data modeling process.
mermaid
classDiagram
    class Article {
        title: string <<Title>>
        content: x-rtf <<Content>>
        author: string <<Author>>
        publishTime: datetime <<Publish Time>>
        status: x-enum = "draft" <<Status>>
        tags: string[] <<Tags>>
        required() ["title", "content", "author"]
        enum_status() ["draft", "published", "archived"]
        display_field() "title"
    }
这些规则将指导AI Agent在数据建模过程中生成符合业务需求的高质量数据模型。