ER diagrams (entity-relationship) are usually the first step in database design. PlantUML’s ER syntax is weaker than Mermaid’s, but it works and stays in the same family as your other UML diagrams.
One-line definition
An ER diagram shows how tables (entities) relate: 1:1, 1:N, N:M, weak entities, derived attributes. It’s the bridge between the domain model and the physical schema.
User ||--o{ Order : places Order ||--|{ OrderItem : contains Product ||--o{ OrderItem : appears in
note top of User ER notation: || exactly one |o zero or one }o many { required (one or more) end note @enduml
Three core relationship styles
1 2 3 4 5
A ||--|| B : A to B, one to one (exactly) A ||--o{ B : A to B, one to many (B end has 0..n) A }o--o{ B : A to B, many to many A ||--|{ B : A to B, one to many (B end required) A }|--|{ B : A to B, many to many (both required)
User ||--o{ Post : writes User ||--o{ Comment : leaves Post ||--o{ Comment : owns Post ||--o{ PostTag : tagged with Tag ||--o{ PostTag : tags @enduml
Review checklist
PK marked with <<PK>>?
FK marked with <<FK>>?
Unique keys marked with <<UK>>?
Cardinality right? ||--o{ vs ||--|{
Table / column names follow conventions?
Many-to-many has a join table?
Self-reference explained?
Tool comparison
Tool
Strength
Weakness
PlantUML ER
Text-first, diff-friendly, same family as UML
Layout less polished
Mermaid erDiagram
Renders natively on GitHub
Limited syntax
draw.io
WYSIWYG, free-form layout
Not text-friendly
dbdiagram.io
Dedicated ER DSL
PNG/SVG, no merge
MySQL Workbench / DataGrip
Complete DDL bidirectional
Heavy; needs Java / desktop
From ER to DDL
PlantUML doesn’t generate DDL directly. Use the ER diagram as the design source, then run migrations via Flyway / Liquibase:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# .github/workflows/db-from-er.yml name:GenerateDDLfromER on: paths: ['docs/erd/**']
jobs: ddl: runs-on:ubuntu-latest steps: -uses:actions/checkout@v4 -name:RenderERdiagrams run:| # auto-render .puml ER files to .svg for review ... -name:Hand-write/reviewmigrations if:github.event_name=='pull_request' run:| # CI checks that docs/erd/*.puml is consistent with migrations/*.sql ...
Note: ER diagram → DDL is not automatic. Indexes, constraints, defaults, character sets need DBA or migration tooling review.
Title: PlantUML ER diagrams: data modeling & table relationships