Skip to content

Instantly share code, notes, and snippets.

@mgwalker
Created November 14, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgwalker/0126e643100df55a0f7f442e8edfa6a1 to your computer and use it in GitHub Desktop.
Save mgwalker/0126e643100df55a0f7f442e8edfa6a1 to your computer and use it in GitHub Desktop.
PostgreSQL dumps into DOT files or PNGs
docker exec <database image> pg_dump -s -U <database username> <database name> | \
# Strip out the namespace because graphviz doesn't know what to do with it
sed 's/ public\./ /g' | \
# Turn that thing into a DOTfile!
docker run -i --rm mgwalker/sql_graphviz:1.0 > docs/database-diagram.dot
docker exec <database image> pg_dump -s -U <database username> <database name> | \
# Strip out the namespace because sql_graphviz doesn't know what to do with it
sed 's/ public\./ /g' | \
# Turn that thing into a DOTfile
docker run -i --rm mgwalker/sql_graphviz:1.0 | \
# And then into a PNG!
docker run -i --rm fgrehm/graphviz dot -Tpng > docs/database-diagram.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment