DEV Community

Sualeh Fatehi
Sualeh Fatehi

Posted on • Updated on

 

Generate (Good Looking) PlantUML Diagrams for Your Database

PlantUML is a domain-specific language to allow you to describe UML and generate diagrams, including entity-relationship diagrams (ERD). You can learn syntax in minutes, but it may take you longer to represent your database. SchemaCrawler generates PlantUML ERD syntax from your existing database. Then you can see what it looks like in the PlantUML online editor, as well as make modifications.

Try it out. Make sure that you have Docker installed on your system, or download SchemaCrawler. Download a sample SQLite database called "chinook-database-2.0.1.sqlite" into your current directory.

Then run a command like:

docker run \
--mount type=bind,source="$(pwd)",target=/home/schcrwlr/share \
--rm -it \
schemacrawler/schemacrawler \
/opt/schemacrawler/bin/schemacrawler.sh \
--server=sqlite \
--database=share/chinook-database-2.0.1.sqlite \
--info-level=standard \
--command script \
--title "Chinook Database Schema" \
--script-language python \
--script plantuml.py
Enter fullscreen mode Exit fullscreen mode

(If you are using PowerShell on Windows, replace the trailing backslash on each line with a back-tick "`".)

Copy the output into the PlantUML online editor and see what it looks like.

It might look something like this:

Schema diagram

Once you have got this working, you can connect to any database - whether Oracle, MySQL, PostgreSQL, Microsoft SQL Server, IBM DB2 or any other database that SchemaCrawler supports.

If you want to customize the script, grab the source from of "plantuml.py" from SchemaCrawler's GitHub repository, and follow instructions on the scripting gist.

To learn about how to use SchemaCrawler, download the SchemaCrawler distribution zip file and go through the examples.

Top comments (3)

Collapse
 
adriens profile image
adriens

Are you thinking about dropping grahviz in favor on PlantUML ?

Collapse
 
sualeh profile image
Sualeh Fatehi

No. I get much finer control with Graphviz directly. In addition to that, I want to offer as many options as possible - mermaid, PlantUML, dbdiagram.io, etc.

Collapse
 
adriens profile image
adriens

Very cool post !