SchemaSpyでDBからER図を生成する
PostgreSQLのER図を生成する
dockerコマンド
docker run -v "${ドキュメントを生成したいディレクトリ}/schema:/output" --net="host" schemaspy/schemaspy:6.1.0 -t pgsql -host ${ホスト}:${ポート番号} -db ${DB名} -u ${ユーザー名} -p ${パスワード}
生成されたドキュメントに上書きしたい場合
schemameta.xml
<schemaMeta xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schemaspy.org/xsd/6/schemameta.xsd" > <comments>Database comment</comments> <tables> <table name="staff" comments="Table comment"> <column name="name" comments="Column comment" /> </table> </tables> </schemaMeta>
dockerコマンド
docker run -v "${ドキュメントを生成したいディレクトリ}/schema:/output" -v "${ドキュメントを生成したいディレクトリ}/schemameta.xml:/schemameta.xml" --net="host" schemaspy/schemaspy:6.1.0 -t pgsql -host ${ホスト}:${ポート番号} -db ${DB名} -u ${ユーザー名} -p ${パスワード} -meta schemameta.xml
propertiesファイルを使う場合
schemaspy.propertiesファイル
# type of database. schemaspy.t=pgsql # database properties: host, db name, name user, password schemaspy.host=${ホスト} schemaspy.db=${DB名} schemaspy.u=${ユーザー名} schemaspy.p=${パスワード}
dockerコマンド
sudo docker run -v "${ドキュメントを生成したいディレクトリ}/schema:/output" -v "${プロパティファイルが置いてあるディレクトリ}/schemaspy.properties:/schemaspy.properties" --net="host" schemaspy/schemaspy:6.1.0
参考URL
まだER図の管理で消耗してるの? SchemaSpy でER図を自動生成して管理する - Qiita