0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

簡単、手軽にER図を作成し、GitHub上で表示させる方法

Last updated at Posted at 2024-01-06

はじめに

この記事は、

  • データベース設計のER図作成
  • GitHub上にER図を表示

この二つを簡単手軽に行う方法を説明します。

ER図作成

まずはデータベースの設計を考えます。
設計の構想に関しては今回は既に済ませてあるものとして、

  • その考えをER図に表したい!
  • ER図を書きながら考えたい!

という風になると思います。
しかし同時に、以下のような気持ちにもなります。

  • ER図を書くための環境準備が面倒!
  • 時間がない!

そんな時に利用したいのがオンラインで使うPlantUMLです。

Web版plantUML

こちらのPlantUMLでコードを入力します。

まず@startumlを入力した後は、各テーブル(エンティティ)を下記のように入力していきます。

plantUMLコード表示
plantuml.md
@startuml internet_tv
' チャンネル
entity "channels"{
  +channel_id [PK]
  ==
  channel_name:varchar(100)
}
' 番組チャンネル
entity "channel_programs"{
  #channel_id [FK(channels,id)]
  #program_id [FK(program,id)]
  time_slot:datetime
}
' 番組
entity "programs"{
  +program_id [PK]
  ==
  *title:varchar(100)
  description:text
}
' シーズン
entity "seasons"{
  +season_id [PK]
  ==
  #program_id [FK(programs,id)] 
  season_number:int 
}
' エピソード
entity "episodes"{
  +episode_id [PK]
  ==
  #season_id [FK(seasons,id)]
  title:varchar(100)
  episode_no:int
  duration:time
  release_date:date
  description:text
  views:int default 0
}
' ジャンル
entity "genres"{
  +genre_id [PK]
  ==
  *name:varchar(50)
}
' 番組ジャンル
entity "program_genres"{
  #program_genres_id:int[FK(channels,id)]
  #genre_id [FK(genres,id)]
  
}
' 視聴数
entity "views"{
  #episode_id [FK(episodes,id)]
  #channel_id [FK(channels,id)]
  time_slot:datetime
  view_count:int
}

その下にリレーションを下記のように入力し、関連性を示した後で@endumlを入力。

plantUMLコード表示
plantuml.md
'リレーション

channels ||--o{ channel_programs
programs ||--o{ channel_programs
programs ||--o{ program_genres
programs ||--|{ seasons
seasons   ||--|{ episodes
episodes  ||--o{ views
genres    ||--o{ program_genres
program_genres ||--o{ programs
channel_programs ||--o{ channels
channel_programs ||--o{ programs
views ||--o{ episodes

@enduml

するとプレビューに以下のようなER図が表示されます。

ER図

GitHub上で画像表示

ER図の作成に成功できたでしょうか。
作成出来たら早速その画像を保存しましょう。

Githubの自分のアカウントに移動し、左上のIssuesをクリックして、新しいissueを作成します。

qiita1

すると以下の画面へと遷移します。

qiita2

Add your description here と表示されている部分に、保存したER図の画像ファイルをドラック&ドロップします。

するとリンクが生成されます。このリンクをコピーした後は、作成しようとしていたissueは破棄して大丈夫です。

画像を貼りたい場所にリンクをペーストすれば画像を埋め込むことができます。

最後に

今回はER図を作成、GitHubにアップロードをする、という一連の作業を簡単な方法で実行してみました。

私自身、ER図の作成という未経験の作業をするのに迷い、時間をかけながら、
Javaや、 Graphvizをインストールし、VSCodeにPlantUMLをインストールし、
VSCode上での作業環境を整えましたが、その利点があまり感じられませんでした。

調べてみるとVSCodeのプロジェクト管理機能を利用し、プロジェクト内の組織化や管理に役立つことができるそうです。
しかし一人で最低限の機能を使用するのであれば、手軽さを重視したこの記事も役立てるのではないかと思い、作成しました。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?