DEV Community

Sualeh Fatehi
Sualeh Fatehi

Posted on • Edited on

7 2

Generate dbdiagram.io Diagrams for Your Database

Generate dbdiagram.io Diagrams for Your Database

dbdiagram.io from Holistics is an online tool to allow you to draw database schema diagrams online using their own Database Markup Language (DBML). You can learn syntax in minutes, but it may take you longer to represent your database. SchemaCrawler generates DBML syntax from your existing database. Then you can see what it looks like in the dbdiagram.io online editor, as well as make modifications. The advantage of having the DBML file is that you can use the DBML CLI to generate DDL to create the database in a variety of dialects, including MySQL and PostgreSQL.

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 \
--script-language python \
--script dbml.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 dbdiagram.io online editor and see what it looks like. 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. And if you like, you can download the DBML CLI to generate DDL to create the database.

You can build the DBML generation in a GitHub Action or GitLab build too. An example is in the schemacrawler/SchemaCrawler-Action-Usage-Example repository.

If you want to customize the script, grab the source from of "dbml.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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
adriens profile image
adriens

Go to killercoda.com/schemacrawler for up-to-date Schemacrawler course

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay