1. Installing GraphViz
    1. Install Homebrew
    2. Install GraphViz
    3. Install Schemacrawler as a command-line tool
  2. How to use
  3. Changing how the diagrams look by editing the behaviour of SchemaCrawler

There often comes the time when you have an existing database and you need to build a nice diagram to analyse it quickly. Here is how to do it using open-source software. We are going to be working on a Mac running macOS 10.14 Mojave, as well as an SQLite database.

The tool that we are going to use is Schemacrawler. It can generate very nice diagrams as you can see at the software’s home page.

Credits go out to the user @dannguyen for his Github Gist that you can find here. Thanks!

Installing GraphViz

First, we need to install GraphViz, an open-source visualization tool. We are going to install it using Homebrew, which is like apt-get for the Mac.

Install Homebrew

If you don’t have it already, you can install Homebrew with the following command.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install GraphViz

Install GraphViz with the following command:

brew install graphviz

Install Schemacrawler as a command-line tool

Heavily adapted from here, only updated to the latest version of SchemaCrawler.

# set up some variables to reduce redundancy

# Download and unzip into /tmp
cd /tmp
curl -Lo ${_SCH_TNAME} ${_SCH_URL}
unzip ${_SCH_TNAME}

# Move subdir from release package into /usr/local/opt
mkdir -p ${_SCH_DIR}
cp -r /tmp/${_SCH_BNAME}/_schemacrawler/ ${_SCH_DIR}

# create the shell script manually
echo '#!/usr/bin/env bash' > ${_SCH_SH}
echo "SC_DIR=${_SCH_DIR}" >> ${_SCH_SH}
echo "java -cp \$(echo \$SC_DIR/lib/*.jar | tr ' ' ':'):\$SC_DIR/config schemacrawler.Main \"\$@\"" \
  >> ${_SCH_SH}

# make it executable and symlink it
chmod +x ${_SCH_SH}
ln -sf ${_SCH_SH} /usr/local/bin/schemacrawler  
echo "done"

The latest releases can be found on the Github page here.

How to use

If you have an SQL script, you need to run it to create a database first:

rm -rf database.db
cat db.sql | sqlite3 database.db

Then, you run schemacrawler to generate a diagram of the database.

  schemacrawler -server sqlite \
    -database database.db \
    -user -password \
    -infolevel standard \
    -command schema \
    -outputformat png \
    -outputfile OUTPUT_IMAGE_FILE.png

Changing how the diagrams look by editing the behaviour of SchemaCrawler

You can change the look of the diagrams generated by SchemaCrawler by editing its properties. Just edit /usr/local/opt/schemacrawler/config/schemacrawler.config.properties.





schemacrawler.graph.graphviz.graph.fontname=Helvetica Neue