SchemaSpy is a tool to document your database simply and easily.
Requirements: Link to heading
Setup Link to heading
- Download jar file from the official schemaspy site (direct link)
- Download postgres jdbc driver from the official postgresql site (direct link)
- Download and setup Graphviz tool
- Windows
- Download a zip file from the link
- Unpack it in the same directory where you store your jar files
- Ubuntu/Debian
sudo apt install graphviz
- Check installation:
dot -V
- CentOS 7
- Download source code from here
- Unpack it:
tar xzf graphviz*.tar.gz
- Go into the new directory with source code:
cd graphviz*
- Fix a problem with PNG (details here):
- Install graphic driver:
sudo yum install gd-devel
- Enable HAVE_GD_PNG flag inside the config.h.im file:
1sed -i 's/#undef HAVE_GD_PNG/#define HAVE_GD_PNG/g' config.h.im
- Install graphic driver:
- Pre-build configuration:
./configure
- Build the source code:
make
- Install into the system:
sudo make install
- Check installation:
dot -V
- You should see no problem and see a version of the tool.
- Windows
Usage Link to heading
1java -jar schemaspy-6.1.0.jar -dp postgresql-9.4.1208.jre6.jar \
2 -t pgsql -host localhost -port 5432 \
3 -db devdb -u devuser -p devpa66 \
4 -o ~/db-schema-dir
Inside the ~/db-schema-dir a static site will be generated which you can open in your browser or upload it to the web server.
If you need more detailed output for the SchemaSpy, then you can specify a java environment variables root.log.level in the command line:
1java -jar schemaspy-6.1.0.jar
2-Droot.log.level=TRACE
3-dp ...
Useful usage script for Postgresql database:
1#!/usr/bin/env bash
2# script: create-db-schema-documentation.sh
3
4# Load all system environments
5. ./.env
6# Create output directory
7output=${OUTPUT:-"./build/db-schema"}
8rm -rf "${output}"; mkdir -p "${output}" 2>/dev/null
9
10schema=
11if [ -n "${PGSCHEMA}" ]; then
12 schema="-s ${PGSCHEMA}"
13fi
14echo "Create database schema: postgres://${PGUSER}:*****@${PGHOST}:${PGPORT}/${PGDATABASE}"
15echo "Output directory ${output}"
16java -jar ./schemaspy-6.1.0.jar \
17 -dp ./postgresql-9.4.1208.jre6.jar \
18 -t pgsql -host "${PGHOST}" -port ${PGPORT} \
19 -db "${PGDATABASE}" -u "${PGUSER}" -p "${PGPASSWORD}" ${schema} \
20 -o "${output}" || exit 1
21echo "Success. Try to open ${output}/index.html in your default browser."
22open "${output}/index.html"
Notes Link to heading
Tested and work good with the versions:
- schemaspy-6.1.0.jar
- postgresql-9.4.1208.jre6.jar
- graphviz-2.38.win.zip - for Windows
- graphviz-2.40.1.src.tar.gz - for CentOS 7