合同会社FoodIT

まだER図で消耗しているの?schemaspyは超便利

post-cover

schemaspyは簡単にDB構造、ER図の作成ができる!

まずは用意しているgithubの説明から

schemaspy_example

ほぼほぼ、README.mdに記載済みなのですが、、、

schemaspyという超絶便利なDBを可視化できるツールがあり、MySQLやPostgresqlなど接続情報を元にテーブル構成やER図の構成をhtml形式で出力してくれるツールです。

ただし、外部キー制約(constraint / foregin)が設定されていないとリレーション構造までは吐き出せないので要注意

使い方!

お好きなところに上記のgithubからcloneしてください

$ git clone git@github.com:sakumoto-shota/schemaspy_exapmle.git
$ cd schemaspy_exapmle

.env.sampleが用意されていますので、そちらに接続情報を記述してください。 試しに行ってみたい場合は、docker-compose-wordpress.ymlを用意しているのでそちらで実行を

$ docker-compose up -d --file docker-compose-wordpress.yml

早速、schemaspyを実行

.env を書き込みます(今回はwordpress)

$ cat .env.sample > .env
$ bash schema.sh 

上記を実行すると・・・

$ bash schema.sh
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Using drivers:jtds-1.3.1.jar, mariadb-java-client-1.1.10.jar
mysql-connector-java-8.0.28.jar, postgresql-42.3.5.jar
  ____       _                          ____
 / ___|  ___| |__   ___ _ __ ___   __ _/ ___| _ __  _   _
 \___ \ / __| '_ \ / _ \ '_ ` _ \ / _` \___ \| '_ \| | | |
  ___) | (__| | | |  __/ | | | | | (_| |___) | |_) | |_| |
 |____/ \___|_| |_|\___|_| |_| |_|\__,_|____/| .__/ \__, |
                                             |_|    |___/

                                              6.1.1-SNAPSHOT

SchemaSpy generates an HTML representation of a database schema's relationships.
SchemaSpy comes with ABSOLUTELY NO WARRANTY.
SchemaSpy is free software and can be redistributed under the conditions of LGPL version 3 or later.
http://www.gnu.org/licenses/

INFO  - Starting Main v6.1.1-SNAPSHOT on docker-desktop with PID 1 (/usr/local/lib/schemaspy/schemaspy-6.1.1-SNAPSHOT.jar started by root in /)
INFO  - The following profiles are active: default
INFO  - Started Main in 6.706 seconds (JVM running for 9.582)
INFO  - Starting schema analysis
INFO  - Connected to MySQL - 5.7.39
INFO  - Gathering schema details
Gathering schema details...............(1sec)
Connecting relationships...............(0sec)
Writing/graphing summary.INFO  - Gathered schema details in 0 seconds
INFO  - Writing/graphing summary
INFO  - Graphviz renderer set to ':cairo'
...ERROR - dot -Tpng:cairo orphans.dot -oorphans.png -Tcmapx: Warning: cell size too small for content
ERROR - dot -Tpng:cairo orphans.dot -oorphans.png -Tcmapx: in label of node wp_users
.....(5sec)
Writing/diagramming detailsINFO  - Completed summary in 5 seconds
INFO  - Writing/diagramming details
..........ERROR - dot -Tpng:cairo wp_users.1degree.dot -owp_users.1degree.png -Tcmapx: Warning: cell size too small for content
ERROR - dot -Tpng:cairo wp_users.1degree.dot -owp_users.1degree.png -Tcmapx: in label of node wp_users
..(5sec)
Wrote relationship details of 12 tables/views to directory '/output' in 15 seconds.
View the results by opening /output/index.html
INFO  - Wrote table details in 5 seconds
INFO  - Wrote relationship details of 12 tables/views to directory '/output' in 15 seconds.
INFO  - View the results by opening /output/index.html

あっという間に完成。 output/index.htmlからさまざまな情報が確認できます。

例えば、、、

scheemaspy_1

ER図なんかも(外部キーが指定されていないのでリレーションは見れません。。)

scheemaSpy orphen

外部制約キーもしっかり書いておくことは重要ですね。

ではでは〜

© 2022 xshsaku foodit.co.jp