PlantUML で ER図

ER図作成というと、ちょっと前は、draw.ioや、古いけど Eclpse プラグインERMaster
あるいは、DBeaber を使っているなら、その中のER図作成ツールなど、、、
あるけど、エンティティを表現するスクリプトをインクルード文法で使い回せるというので
PlantUML の ER図も魅力はある。
https://plantuml.com/ja-dark/ie-diagram

entities.pu

package "開発システム" as target_system {

	entity "エンティティ1\nEntity01" as e01 {
	  +e1_id  [PK] : int
	  --
	  name [名前]: varchar(60)
	  description [説明] : text
	}
	
	entity "エンティティ2\nEntity02" as e02 {
	  +e2_id [PK] : int
	  --
	  *e1_id : int
	  other_details [備考] : text
	}

	entity "エンティティ3\nEntity03" as e03 {
	  +e3_id [PK] : int
	  --
	  -e1_id : int
	  other_details [備考] : text
	}

}

このテーブル定義をつかう PlantUML は。!include {定義ファイル} で使い回せる

@startuml ERskin rose
skinparam shadowing false
hide circle
!include entities.pu

e01 ||-u-o{ e02
e01 |o--o{ e03

@enduml

カーディナリティの書式
1対1

e01 -- e02

必須1

e01 --|| e02

0以上、n個

e01 --o{ e02

左辺の場合は、

e01 }o-- e02

1以上、n個

e01 --|{ e02

左辺の場合は、

e01 }|-- e02