Replies: 3 comments 2 replies
-
hot fire flame 🔥 right here |
Beta Was this translation helpful? Give feedback.
-
This is so cool!
|
Beta Was this translation helpful? Give feedback.
-
Nice! To follow up on Pat's notes, a similar (but slightly different) approach would be to consume the dbt manifest and catalog files directly instead of querying the DW. This repo is a python script that creates a The advantage of this approach is that it is compatible across Warehouses. |
Beta Was this translation helpful? Give feedback.
-
Background
What is an ERD?
An ERD, or entity-relationship diagram, is a graphical representation of data - showing entities, their attributes, and how they can relate to other entities.
Setup
Docs (source code)
Create a docs block containing a link to your soon-to-be-created ERD:
You'll notice that I created an
assets
folder to store my ERDs - the location is up to you!Then, add your block to a yml file:
Python (source code)
The python script should do the following:
Identify the schemas you'd like to generate an ERD for:
Run a job specifically created for a merge to main. Think of this as a good time to run those newly merged models and anything downstream (or simply a
dbt compile
anddbt docs generate
will suffice)Create a database URL. I'm using the snowflake-sqlalchemy package and the
URL
utility to create my database URL. Other dialects can be found here.Finally, create an ERD using the eralchemy package.
Github Action (source code)
The action will be triggered when a pull request is merged to our main branch:
An important callout here is that we need to install
graphviz
and its dependencies in order forpygraphviz
to work properly.Then, our python dependencies are installed via
requirements.txt
and our python script from above is run. Ensure that you have the appropriate environment variables set via secrets stored within your repo.The python script will create
.png
files and the last step will add those newly created files directly to yourmain
branch.Caveats
I'm using the dbt_constraints package to automatically create foreign keys via an
on-run-end
hook. Currently, this package is only compatible with Snowflake and PostgreSQL.Output
Beta Was this translation helpful? Give feedback.
All reactions