LoginSignup
10
11

More than 5 years have passed since last update.

ERAlchemyでPostgreSQLからER図生成

Posted at

ERAlchemy

Alexis-benoist/eralchemy

ERAlchemy generates Entity Relation (ER) diagram (like the one below) from databases or from SQLAlchemy models.

これで手軽にER図が生成できる。

インストール

  • CentOS 7
  • Python2.7

pip をインストールしていなければ以下参照
CentOS7にpipをインストール。ついでにiPythonも。 - Qiita

yum install gcc python-devel graphviz-devel
pip install eralchemy

で、postgresに接続するためにPsycopgをインストール
PostgreSQL + Python | Psycopg

yum install postgresql-devel
pip install psycopg2

以上、準備完了

PDFを出力

eralchemy -i 'postgresql+psycopg2://[username]:[password]@[host]:[port]/[database]' -o hoge.pdf

ちなみに対応形式は

  • .png(PNG)
  • .pdf(PDF)
  • .dot(GraphViz)
  • .er(markdown)

スキーマ指定について

以下のようにスキーマを指定して出力できるが…

eralchemy -i 'postgresql+psycopg2://[username]:[password]@[host]:[port]/[database]' -s [schema] -o hoge.pdf

リレーションのひも付けがうまくできていない。

eralchemy -i 'postgresql+psycopg2://[username]:[password]@[host]:[port]/[database]' -s [schema] -o hoge.dot

:arrow_up: で出力されたファイルを確認してみると。

~~~
"[schema].User" [label=<<FONT FACE="Helvetica">...
~~~
"[schema].TeamMember" [label=<<FONT FACE="Helvetica">...
~~~
"User" -- "[schema].TeamMember" [taillabel=<<FONT>0..N</FONT>>,headlabel=<<FONT>{0,1}</FONT>>];
~~~

リレーションのひも付けを記載しているところで親のみスキーマ名が付与されていない。
原因は後でおってみる。

10
11
0

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
10
11