When to use this skill
Use this skill for MySQL database modeling and creation when you need to:
- Create data models from business requirements
- Design database schemas using Mermaid class diagrams
- Map business fields to MySQL data types
- Define entity relationships and constraints
- Create or update database models in CloudBase
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)
How to use this skill (for a coding agent)
Follow the modeling workflow
- 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
Apply generation rules strictly
- 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
Use tools correctly
- Call data model creation tools when user provides complete 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
Data Model AI Modeling Professional Rules
AI Modeling Expert Prompt
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:
Generation Rules
Type Mapping Priority: When user-described fields match the mapping relationship, prioritize using type as the field type. Mapping relationships are as follows:
| Business Field |
type |
| Text |
string |
| Number |
number |
| Boolean |
boolean |
| Enum |
x-enum |
| Email |
email |
| Phone |
phone |
| URL |
url |
| File |
x-file |
| Image |
x-image |
| Rich Text |
x-rtf |
| Region |
x-area-code |
| Time |
time |
| Date |
date |
| DateTime |
datetime |
| Object |
object |
| Array |
string[] |
| Location |
x-location |
Naming Convention: Convert Chinese descriptions to English naming (except enum values). Use PascalCase for class names, camelCase for field names.
Field Visibility: Use default visibility for fields, do not add "+" or "-".
Array Types: When descriptions include array types, use specific array formats such as string[], number[], x-rtf[], etc.
Chinese Administrative Regions: When involving Chinese administrative regions like "province/city/district", use x-area-code field type.
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.
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.
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.
Field Descriptions: For each field definition in user descriptions, use <<description>> format at the end of the definition line, e.g., name: string <<Name>>.
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.
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.
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.
Naming: Field names and descriptions in Mermaid should be concise and accurately expressed.
Complexity Control: Unless user requires, control complexity, e.g., number of classes should not exceed 5, control field complexity.
Standard Example
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
- 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
- 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
3. Model Validation Phase
- Check model completeness and consistency
- Verify relationship rationality
- Confirm field constraint correctness
- Check naming convention compliance
MySQL Data Type Support
Basic Type Mappings
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
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
- When user explicitly requests data model creation
- When user provides complete business requirement descriptions
- When user provides mermaid classDiagram
- When need to update existing data model structure
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
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
Best Practices
Model Design Principles
- Single Responsibility: Each entity class is responsible for only one business concept
- Minimize Dependencies: Reduce unnecessary relationships
- Extensibility: Reserve field space for future expansion
- Consistency: Maintain consistency in naming and type usage
Performance Considerations
- Index Design: Create indexes for commonly queried fields
- Field Length: Reasonably set string field lengths
- Relationship Optimization: Avoid excessive many-to-many relationships
- Data Sharding: Consider table sharding strategies for large tables
Security Standards
- Sensitive Fields: Encrypt storage for sensitive information like passwords
- Permission Control: Clarify read/write permissions for fields
- Data Validation: Set appropriate field constraints
- Audit Logs: Add operation records for important entities
Common Business Scenario Templates
User Management System
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
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
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.
1---2name: data-model-creation-23description: Professional rules for AI-driven data modeling and creation. Use this skill when users need to create and manage MySQL databases, design data models using Mermaid ER diagrams, and implement database schemas.4alwaysApply: false5metadata:6 source: https://skillmd.com/skills/diegosouzapw/data-model-creation-27---89## When to use this skill1011Use this skill for **MySQL database modeling and creation** when you need to:1213- Create data models from business requirements14- Design database schemas using Mermaid class diagrams15- Map business fields to MySQL data types16- Define entity relationships and constraints17- Create or update database models in CloudBase1819**Do NOT use for:**20- Querying or manipulating existing data (use database skills)21- NoSQL database design (use NoSQL skills)22- Frontend data structures (use appropriate frontend skills)2324---2526## How to use this skill (for a coding agent)27281. **Follow the modeling workflow**29 - Business analysis phase: Analyze user requirements, identify core entities and relationships30 - Mermaid modeling phase: Create mermaid classDiagram following generation rules31 - Model validation phase: Check completeness, consistency, and correctness32332. **Apply generation rules strictly**34 - Use correct type mappings (string, number, boolean, x-enum, etc.)35 - Convert Chinese to English naming (PascalCase for classes, camelCase for fields)36 - Define required(), unique(), display_field() functions when needed37 - Use proper relationship notation with field names38393. **Use tools correctly**40 - Call data model creation tools when user provides complete business requirements41 - Use `mermaidDiagram` parameter with complete mermaid classDiagram code42 - Set `publish` to false initially, create then publish separately43 - Choose appropriate `updateMode` for new or existing models4445---4647# Data Model AI Modeling Professional Rules4849## AI Modeling Expert Prompt5051As 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:5253### Generation Rules54551. **Type Mapping Priority**: When user-described fields match the mapping relationship, prioritize using type as the field type. Mapping relationships are as follows:56 | Business Field | type |57 | --- | --- |58 | Text | string |59 | Number | number |60 | Boolean | boolean |61 | Enum | x-enum |62 | Email | email |63 | Phone | phone |64 | URL | url |65 | File | x-file |66 | Image | x-image |67 | Rich Text | x-rtf |68 | Region | x-area-code |69 | Time | time |70 | Date | date |71 | DateTime | datetime |72 | Object | object |73 | Array | string[] |74 | Location | x-location |75762. **Naming Convention**: Convert Chinese descriptions to English naming (except enum values). Use PascalCase for class names, camelCase for field names.77783. **Field Visibility**: Use default visibility for fields, do not add "+" or "-".79804. **Array Types**: When descriptions include array types, use specific array formats such as string[], number[], x-rtf[], etc.81825. **Chinese Administrative Regions**: When involving Chinese administrative regions like "province/city/district", use x-area-code field type.83846. **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.85867. **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.87888. **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.89909. **Field Descriptions**: For each field definition in user descriptions, use `<<description>>` format at the end of the definition line, e.g., `name: string <<Name>>`.919210. **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.939411. **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.959612. **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.979813. **Naming**: Field names and descriptions in Mermaid should be concise and accurately expressed.9910014. **Complexity Control**: Unless user requires, control complexity, e.g., number of classes should not exceed 5, control field complexity.101102### Standard Example103104```mermaid105classDiagram106 class Student {107 name: string <<Name>>108 age: number = 18 <<Age>>109 gender: x-enum = "Male" <<Gender>>110 classId: string <<Class ID>>111 identityId: string <<Identity ID>>112 course: Course[] <<Courses>>113 required() ["name"]114 unique() ["name"]115 enum_gender() ["Male", "Female"]116 display_field() "name"117 }118 class Class {119 className: string <<Class Name>>120 display_field() "className"121 }122 class Course {123 name: string <<Course Name>>124 students: Student[] <<Students>>125 display_field() "name"126 }127 class Identity {128 number: string <<ID Number>>129 display_field() "number"130 }131132 %% Relationships133 Student "1" --> "1" Identity : studentId134 Student "n" --> "1" Class : student2class135 Student "n" --> "m" Course : course136 Student "n" <-- "m" Course : students137 %% Class naming138 note for Student "Student Model"139 note for Class "Class Model"140 note for Course "Course Model"141 note for Identity "Identity Model"142```143144## Data Model Creation Workflow145146### 1. Business Analysis Phase147- Carefully analyze user's business requirement descriptions148- Identify core entities and business objects149- Determine relationships between entities150- Clarify required fields, unique constraints, and default values151152### 2. Mermaid Modeling Phase153- Strictly follow the above generation rules to create mermaid classDiagram154- Ensure field type mappings are correct155- Properly handle relationship directions and cardinalities156- Add complete Chinese descriptions and comments157158### 3. Model Validation Phase159- Check model completeness and consistency160- Verify relationship rationality161- Confirm field constraint correctness162- Check naming convention compliance163164## MySQL Data Type Support165166### Basic Type Mappings167- `string` → VARCHAR/TEXT168- `number` → INT/BIGINT/DECIMAL169- `boolean` → BOOLEAN/TINYINT170- `date` → DATE171- `datetime` → DATETIME172- `time` → TIME173174### Extended Type Mappings175- `x-enum` → ENUM type176- `x-file`/`x-image` → File path storage177- `x-rtf` → LONGTEXT rich text178- `x-area-code` → Region code179- `x-location` → Geographic location coordinates180- `email`/`phone`/`url` → VARCHAR with validation181182### Relationship Implementation183- One-to-one: Foreign key constraints184- One-to-many: Foreign key associations185- Many-to-many: Intermediate table implementation186- Self-association: Same table foreign key187188## Tool Usage Guidelines189190### Tool Call Timing1911. When user explicitly requests data model creation1922. When user provides complete business requirement descriptions1933. When user provides mermaid classDiagram1944. When need to update existing data model structure195196### Parameter Usage Guide197- `mermaidDiagram`: Complete mermaid classDiagram code198- `publish`: Whether to publish model immediately (recommend default to false, create then publish)199- `updateMode`: Create new model or update existing model200201### Error Handling Strategy202- Syntax errors: Check Mermaid syntax format203- Field type errors: Verify type mapping relationships204- Relationship errors: Check relationship directions and cardinalities205- Naming conflicts: Provide renaming suggestions206207## Best Practices208209### Model Design Principles2101. **Single Responsibility**: Each entity class is responsible for only one business concept2112. **Minimize Dependencies**: Reduce unnecessary relationships2123. **Extensibility**: Reserve field space for future expansion2134. **Consistency**: Maintain consistency in naming and type usage214215### Performance Considerations2161. **Index Design**: Create indexes for commonly queried fields2172. **Field Length**: Reasonably set string field lengths2183. **Relationship Optimization**: Avoid excessive many-to-many relationships2194. **Data Sharding**: Consider table sharding strategies for large tables220221### Security Standards2221. **Sensitive Fields**: Encrypt storage for sensitive information like passwords2232. **Permission Control**: Clarify read/write permissions for fields2243. **Data Validation**: Set appropriate field constraints2254. **Audit Logs**: Add operation records for important entities226227## Common Business Scenario Templates228229### User Management System230```mermaid231classDiagram232 class User {233 username: string <<Username>>234 email: email <<Email>>235 password: string <<Password>>236 avatar: x-image <<Avatar>>237 status: x-enum = "active" <<Status>>238 required() ["username", "email"]239 unique() ["username", "email"]240 enum_status() ["active", "inactive", "banned"]241 display_field() "username"242 }243```244245### E-commerce System246```mermaid247classDiagram248 class Product {249 name: string <<Product Name>>250 price: number <<Price>>251 description: x-rtf <<Product Description>>252 images: x-image[] <<Product Images>>253 category: string <<Category>>254 stock: number = 0 <<Stock>>255 required() ["name", "price"]256 display_field() "name"257 }258 class Order {259 orderNo: string <<Order Number>>260 totalAmount: number <<Total Amount>>261 status: x-enum = "pending" <<Order Status>>262 createTime: datetime <<Create Time>>263 required() ["orderNo", "totalAmount"]264 unique() ["orderNo"]265 enum_status() ["pending", "paid", "shipped", "completed", "cancelled"]266 display_field() "orderNo"267 }268```269270### Content Management System271```mermaid272classDiagram273 class Article {274 title: string <<Title>>275 content: x-rtf <<Content>>276 author: string <<Author>>277 publishTime: datetime <<Publish Time>>278 status: x-enum = "draft" <<Status>>279 tags: string[] <<Tags>>280 required() ["title", "content", "author"]281 enum_status() ["draft", "published", "archived"]282 display_field() "title"283 }284```285286These rules will guide AI Agents to generate high-quality, business-requirement-compliant data models during the data modeling process.287