Package: dbt-diagrams
dbt-diagramsThis tool allows you togenerate an Entity Relationship Diagram (ERD) based onmetaconfig in your dbt model docs. Currently it relies onMermaidto render the output. You can choose to render your output inside your dbt docs directly, or store it as a separate SVG image.Enable general Mermaid rendering capabilities to your dbt docs. Every Markdown code block tagged withmermaidwill be rendered.[!TIP]Demo Jaffle Shop docs pagesInstallation instructionsAsdbt-diagramsis just a Python package. Install it using your favourite Python package manager (e.g.pip install dbt-diagrams). In case you want to render your ERD to a SVG image, you will have to install thedbt-diagrams[svg]extras package as well.Usage (1): add Mermaid rendering to dbt docsSimply rundbt-diagrams docs generateinstead ofdbt docs generate. Any Markdown code block tagged withmermaidwill now be picked up and rendered as an image.Usage (2): specify ERD inmetablocks and render in dbt docsThis will achieve the same functionality as (1), plus the following: let's say you have the following models defined in your dbt projectversion:2models:-name:customersdescription:>This table has basic information about a customer, as well as some derived facts based on a customer's orders```mermaid[erd="customer_erd"]```config:meta:erd:connections:-diagram:customer_erdtarget:orderssource_cardinality:onetarget_cardinality:one_or_morelabel:createscolumns:-name:customer_iddescription:This is a unique identifier for a customer-name:first_namedescription:Customer's first name. PII.-name:last_namedescription:Customer's last name. PII.-name:ordersdescription:>This table has basic information about orders, as well as some derived facts based on payments```mermaid[erd="customer_erd"]```columns:-name:order_id-name:customer_iddescription:Foreign key to the customers table-name:order_datedescription:Date (UTC) that the order was placed-name:statusdescription:'{{doc("orders_status")}}'Using themetasection of a model, you can define ERD connections to other models. Based on these connections and other table attributes the ERD can be generated. Thetargetattribute is another dbt model name. Accepted relation cardinalities areone,zero_or_one,zero_or_moreorone_or_more. Use thelabelattribute to specify a human readable interpretation to a relation. Thediagramis optional and allows you to add a name to your ERD. This is useful in case you want to define multiple ERDs and reference them in dbt docs directly.Notice themermaid[erd="cusomer_erd"]expressions in thecustomersandordersmodel descriptions. When runningdbt-diagrams docs generate, this will be replaced by the ERD Mermaid definition so that your ERD can be rendered in any dbt docs page.erDiagram
   customers ||--|{ orders : creates

   customers {
    STRING customer_id
    STRING first_name
    STRING last_name
   }

   orders {
    STRING order_id
    STRING customer_id
    DATE order_date
    STRING status
   }Usage (3): specify ERD inmetablocks and render as SVGGiven the same setup as above, you can also render your output to SVG:Make sure you installed thedbt-diagrams[svg]extras. This will install a headless browser in which Mermaid can run.Rundbt-diagrams render-erds -dbt-target-dir target --format svg --output ./out. This will use themanifestandcatalogfiles from./targetto render all defined ERDs as SVG. All detected diagrams will be stored as SVG files in the./outfolder.ERD Definition schemaEveryerdsection inside ametablock of a model will be picked up. It should look like the following:erd:connections:-diagram:<Optional. This connection will be added to a diagram of this name>target:<Required. Other model name>source_cardinality:<Required. One of {zero_or_one, one, zero_or_more, one_or_more}>target_cardinality:<Required. One of {zero_or_one, one, zero_or_more, one_or_more}>label:<Optional. Any string that describes the relation from this model to target model.>