ERD Template
Template untuk mendokumentasikan database schema menggunakan ERD (Entity Relationship Diagram) dengan Mermaid.📊 Basic ERD Template
🎯 Complete E-Commerce ERD Example
📝 ERD Notation Guide
Relationship Cardinality
| Symbol | Meaning | Example |
|---|---|---|
||--o{ | One to Many | User has many Orders |
}o--|| | Many to One | Order belongs to User |
||--|| | One to One | Order has one Payment |
}o--o{ | Many to Many | Product has many Tags |
||--o| | One to Zero or One | Order may have Shipment |
Field Constraints
| Constraint | Meaning |
|---|---|
PK | Primary Key |
FK | Foreign Key |
UK | Unique Key |
NOT NULL | Cannot be null |
DEFAULT value | Default value |
>= 0 | Minimum value |
Max N | Maximum length |
Data Types
| Type | Description | Example |
|---|---|---|
uuid | UUID v4 | 550e8400-e29b-41d4-a716-446655440000 |
string | VARCHAR | "John Doe" |
text | TEXT/LONGTEXT | Long description |
int | INTEGER | 42 |
decimal | DECIMAL(10,2) | 99.99 |
boolean | BOOLEAN | true/false |
enum | ENUM | "active", "inactive" |
json | JSON | {"key": "value"} |
timestamp | TIMESTAMP | 2024-01-01T10:00:00Z |
🎨 Styling Tips
Color Coding (Optional)
Mermaid tidak support native color di ERD, tapi bisa di-customize via CSS:📚 Best Practices
1. Naming Conventions
1. Naming Conventions
- Tables: UPPER_SNAKE_CASE atau PascalCase
- Columns: snake_case
- Foreign Keys:
{table}_id(e.g.,user_id) - Junction Tables:
{table1}_{table2}(e.g.,product_tag)
2. Field Documentation
2. Field Documentation
- Selalu tambahkan constraint info (PK, FK, UK, NOT NULL)
- Dokumentasikan enum values
- Tambahkan default values
- Jelaskan business rules di description
3. Relationship Documentation
3. Relationship Documentation
- Gunakan nama relationship yang jelas
- Dokumentasikan ON DELETE behavior
- Jelaskan business logic di relationship
4. Maintenance
4. Maintenance
- Update ERD setiap ada perubahan schema
- Version control ERD bersama migration
- Review ERD saat code review
🔄 Migration from ERD
Setelah ERD dibuat, generate migration SQL:- MySQL Migration
- Down Migration
📊 Tools & Resources
Mermaid Live Editor
Preview dan edit ERD secara real-time
dbdiagram.io
Alternative tool untuk design database
MySQL Workbench
Visual database design tool
Atlas
Database schema as code tool
Template Usage: Copy ERD template ini dan sesuaikan dengan schema database Anda. Pastikan semua relationship dan constraint terdokumentasi dengan jelas.