Other Diagrams Example
SchemaCrawler can generate diagrams in formats beyond its built-in GraphViz generated output by combining its script command with small Python scripts. This example shows how to produce Mermaid, DBML for dbdiagram.io, and PlantUML entity-relationship diagrams.
How to Run
Before running this example, complete the setup in Getting Started.
Replace with the connection options for your chosen database. See Getting Started.
Run through all the examples on diagrams page.
Resource Files
The script command passes SchemaCrawler’s in-memory catalog model to a Python script. The Python script then walks the catalog’s tables and relationships and emits the diagram source text to stdout.
Python Scripts
The three Python scripts (mermaid.py, dbml.py, plantuml.py) each receive the SchemaCrawler catalog as a scripting context and emit diagram source in their respective formats:
| Script | Output format | View at |
|---|---|---|
mermaid.py | Mermaid erDiagram syntax | Mermaid Live Editor |
dbml.py | DBML (Database Markup Language) | dbdiagram.io |
plantuml.py | PlantUML @startuml entity diagram | PlantUML server |
Each script iterates over the filtered tables (AUTHORS and BOOKS in the PUBLIC.BOOKS schema) and their foreign-key relationships, then serialises them in the target notation.
Place each script file in your working directory. It will be accessible inside the container as
share/mermaid.py,share/dbml.py, orshare/plantuml.py.
How to Experiment
- Modify the
--schemasand--tablesfilter options in the run command to include more (or fewer) tables in the diagram. - Edit the Python scripts to customise the diagram output — for example, adding column data types to the Mermaid diagram or changing the DBML colour theme.
- Add a new Python script to emit a different diagram format (e.g., Graphviz DOT, Nomnoml) and run it the same way:
schemacrawler <connection-options> ... --script share/myformat.py > share/output.txt.