ERDs in Org Mode

In the past few months, I've had a number of contracting and side projects crop up that have required a lot of software architecture work, including developing Entity Relationship Diagrams, which I find helpful when planning out a project (and especially when working with other people not as familiar with the subject matter). While at work, I have a bevvy of SaaS options to do much of this (primarily with Lucidchart), I wanted to see what options there were in OSS.

I've mentioned before that org-mode is my daily multitool for organization, prototyping, and experimentation. As such, I figured there had to be some kind of literate programming solution for ERDs, given that I've used CLI tools like graph viz in the past.

In one of my projects, we're working on integrating Mermaid into our UI, and a quick web search revealed that there was more than just a JS library, there's also a command line tool!

...and reasonable supposition based on the ingenuity of emacs/org-mode users led me to search for an org-mode/Mermaid integration...

which of course there was: ob-mermaid from Alexei Nunez!

The setup in Doom Emacs was straightforward (just follow the Github instructions), and now I can easily generate SVGs of my ERDs turning this code:

#+begin_src mermaid :file blt_erd.svg :background-color #FFFFFF
erDiagram
    BUILDING {
        INTEGER id  PK
        TEXT project_name
        TEXT project_country
        TEXT project_postal_code
        TEXT asset_type
        TEXT building_construction_type
        TEXT building_use_type
        TEXT project_units
        TEXT gfa_measurement_method
        TEXT gross_floor_area
        TEXT enclosed_parking_area
    }
    LCA_METADATA {
        INTEGER id PK
        INTEGER building_id FK
        TEXT tool_lca
        TEXT project_phase_at_time_of_assessment
        INTEGER operational_energy_included
        INTEGER biogenic_carbon_included
        INTEGER substructure_included
        INTEGER shell_superstructure_included
        INTEGER shell_exterior_enclosure_included
        INTEGER interior_construction_included
        INTEGER interior_finishes_included
        INTEGER services_mep_included
        INTEGER sitework_included
        INTEGER equipment_included
        INTEGER furnishings_included
    }
    TALLY_RECORD {
        INTEGER    id PK
        INTEGER lca_id FK
        TEXT revit_design_option
        TEXT revit_general_category
        TEXT revit_category
        TEXT revit_type
        TEXT revit_famly_name
        TEXT revit_material_name
        TEXT revit_building_element
        REAL thickness_of_material
        INTEGER total_instance_count
        TEXT cumulative_material_volume
        REAL cumulative_material_area
        REAL cumulative_instance_volume
        REAL cumulative_instance_area
        REAL cumulative_instance_length
        REAL cumulative_instance_perimeter
        TEXT tally_entry_division
        TEXT tally_entry_category
        TEXT tally_entry_name
        TEXT material_group
        TEXT material_name
        TEXT life_cycle_stage
        INTEGER service_life
        REAL acidification_potential_total
        REAL eutrophication_potential_total
        REAL global_warming_potential_total
        REAL ozone_depletion_potential_total
        REAL smog_formation_potential_total
        REAL primary_energy_demand_total
        REAL nonrenewable_energy_demand_total
        REAL renewable_energy_demand_total
        REAL mass_total
        TEXT timestamp
    }
    BUILDING ||--o{ LCA_METADATA : "has many"
    LCA_METADATA ||--o{ TALLY_RECORD : "contains many"
#+end_src

into this diagram:

ER Diagram

So far ob-mermaid seems to support all the features of Mermaid (at least what I need)!