Create Mermaid-Js ERD diagrams from existing tables

Mermerd

Create Mermaid-Js ERD diagrams from existing tables.

Features

  • Supports PostgreSQL and MySQL
  • Select from available schemas
  • Select only the tables you are interested in
  • Show only the constraints that you are interested in
  • interactive cli (multiselect, search for tables and schemas, etc.)

Why would I need it / Why should I care?

Documenting stuff and keeping it updated is hard and tedious, but having the right documentation can help to make the right decisions. Mermerd was designed to be able to export an existing database schema in a format that can be used to prototype and plan new features based on the existing schema. The resulting output is an ERD diagram in Mermaid-Js format that can easily be updated and extended.

How does it work

  1. Specify the connection string (via parameter or interactive cli)
  2. Specify the schema that should be used (via parameter or interactive cli)
  3. Select the tables that you are interested in (multiselect, at least 1)
  4. Enjoy you current database schema in Mermaid-JS format
example.mp4

Parameters

Some configurations can be set via command line parameters. The parameters can also be viewed via mermerd -h

Parameter Description Example
c the connection string mermerd -c="postgresql://user:password@localhost:5432/dvdrental"
s the schema mermerd -s=public
ac toggle if all constraints should be included (default false) 1 mermerd -ac

Connection strings

Examples for connection strings:

  • postgresql://user:password@localhost:5432/yourDb
  • mysql://root:password@tcp(127.0.0.1:3306)/yourDb

How can I write/update Mermaid-JS diagrams?

  • All information can be found here: Mermaid-JS
  • I also recommend using an IDE with an Mermaid-JS extension, e.g. VS Code

Roadmap

  • Unit tests
  • Configurable suggestions for connection string input
  • Support }o--o| relation (currently displayed as }o--||)
  • Improve output file naming

Footnotes

  1. If the flag -ac is provided, mermerd will print out all constraints of the selected tables, even when the resulting constraint is not in the list of selected tables. These tables do not have any column infos and are only present via their table name.

Comments
  • SSL connection does not work properly

    SSL connection does not work properly

    I've been trying to get this to work with SSL and am running into this error from the docker logs: LOG: could not accept SSL connection: sslv3 alert bad certificate

    Here is my connection string that does not work: mermerd -c postgresql://david:password@localhost:5433/david?sslmode=verify-full&sslcert=$PWD/packages/david-db/src/client.crt&sslkey=$PWD/packages/david-db/src/client.key&sslrootcert=$PWD/packages/david-db/src/ca.crt -s public --useAllTables -o docs/erd.mmd

    Using the same certificates with docker works fine: docker exec -i david-test psql -U david -d david sslmode=verify-full sslrootcert=$PWD/packages/david-db/src/ca.crt sslkey=$PWD/packages/david-db/src/client.key sslcert=$PWD/packages/david-db/src/client.crt

    The certificates also work correctly with pgAdmin and knex migrations.

  • sql: Scan error on column index 2, name

    sql: Scan error on column index 2, name "is_primary"

    Hi,

    Just installed mermerd, look like a nice tool.

    I tried to run it against a mysql database and get the following error

    • mermerd 0.4.0
    • macos amd
    INFO[0006] Got tables                                    count=38
    [=>                  ]Getting columns and constraintsERRO[0008] Getting columns failed | sql: Scan error on column index 2, name "is_primary": sql/driver: couldn't convert 2 into type bool
    ERRO[0008] sql: Scan error on column index 2, name "is_primary": sql/driver: couldn't convert 2 into type bool
    
    
    X Something went wrong!
    

    Any idea ? :-)

  • Add --selectedTables switch

    Add --selectedTables switch

    ERD generation in CI/CD is a pretty common workflow, and some projects understandably will not want to introduce a memerd configuration file to their projects simply to specify which tables to include in the diagram.

    This simple modification exposes the --selectedTables switch, so it's not necessary to create a configuration file to select tables for diagram inclusion.

  • Add debug mode

    Add debug mode

    Hello, i was really hyped about your tool for documentation :).

    I just tried it on my DB and it does not want to do the job :

    more than one row in subquery
    

    And i have no clue about what is the problem.

    Maybe a --debug flag could be postponed to understand better why it would not work ?

    What do you think ?

  • feature request: support for wildcard schema/useAllSchemas flag/config

    feature request: support for wildcard schema/useAllSchemas flag/config

    One of the reasons we're using a tool to map out oru DC for our documentation is that our DB isn't... cleanly seperated. Because of that individually mapping schemas means the bridges get missed, is there a way to add either a wildcard option in the checma selection/config and/or add a useAllSchemas flag/config to allow mapping between schemas?

  • Primary Key & Foreign Key not shown

    Primary Key & Foreign Key not shown

    Hi, I really love this tool. I would like to know is it possible to output the primary key & foreign key label ?

    The command I use:

    mermerd --encloseWithMermaidBackticks \
        -c "postgresql://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSL_MODE}" \
        --outputFileName ./doc/erd.md \
        --schema public \
        --useAllTables \
        --showAllConstraints
    

    I expect something like this:

    erDiagram
        users ||--o{ books: own
    
    users {
        uuid id "pk"
        text email
        text password_hash
        text name
        text role
        text status
    }
    
    books {
        uuid id "pk"
        uuid owned_by "fk"
    }
    
  • Add support for postgres enums

    Add support for postgres enums

    We have a lot of enums in our production database, so I want to show them in ERD diagram. Right now they appear simply as USER-DEFINED. How do you look at fetching data about enums from DB and fitting those values into the comment section of describing tables (here) How it works right now:

    erDiagram
      table_name {
              USER-DEFINED best_column
      }
    

    How I propose it to look like:

    erDiagram
      table_name {
              myFavouriteEnumType best_column "MyFavouriteEnumVal1, MyFavouriteEnumVal2, MyFavouriteEnumVal3"
      }
    

    If you're okey with this proposal I can make PR later

  • add config: allow surrounding output with backticks

    add config: allow surrounding output with backticks

    Hi,

    thank you for this amazing work.

    I needed a few extra features for a project of mine, so I added them myself.

    Since I don't know if you are welcoming new additions or if this feature even is on your roadmap, feel free to reject this PR.

    If you want to discuss around this work, please do.

    Anyway, if you would like to know more about what I did:

    The idea was that I wanted to be able to directy preview output file. I therefore needed it to have the proper backticks characters for parsers to understand it.

    • Added a new config entry: encloseWithMermaidBackticks (boolean)
    • If this entry is not set, or false, behaviour will be default (nothing more than what mermerd already does)
    • If this entry is set to true, it will prefix output by "mermaid", and insert "" right before the ending new lines.

    Have a great day,

  • Cool idea of a tool!

    Cool idea of a tool!

    Hey @KarnerTh!

    This looks really cool and a promising idea. My immediate reflection is

    • Would it be possible to opt in on all tables?
    • Not force input interaction and relay on config/inputs
    • Make it more accessible to use in a CI / CD pipeline.
      • Maybe host it on docker?

    Eager to see more of this. Good work so far!

  • Enable the copy-button

    Enable the copy-button

    Proposed formatting enables the copy-button which appears in the top right corner of the copy widget. Which makes copy'n pasting the code fragment much easier. image

  • Missing template diagram/erd_template.gommd in v0.2.0

    Missing template diagram/erd_template.gommd in v0.2.0

    Thanks so much for the quick fix in #8, when trying it out on the schema that produced that issue for me I ran into another issue though. Turning on the debug flag (thanks for that too) I got this output:

    .  ..___.__ .  ..___.__ .__ 
    |\/|[__ [__)|\/|[__ [__)|  \
    |  |[___|  \|  |[___|  \|__/ (0.2.0)
    
    Create MermaidJs diagrams from your database
    
    INFO[0000] Got tables                                    count=1
    INFO[0000] Got columns and constraints constraints       columns=5 constraints=0
    ERRO[0000] Could not load template file | open diagram/erd_template.gommd: no such file or directory 
    

    If I manually download that file and place it in the path it works, but I'm guessing that it was meant to be bundled into the binary.

  • Feature: omit non-relation columns

    Feature: omit non-relation columns

    First of all, thanks for building this tool! It's become part of my toolbox for working with large complex relational schemas.

    One thing I'd love to see is the ability to filter out all the columns from a table that aren't used as a foreign key. This helps cut down on noise when trying to explain relationships between tables.

    I'm happy to open a PR for this if pointed in the right direction 👍

  • Duplication of columns on each table

    Duplication of columns on each table

    Love this tool! Using it for a MySQL instance hosted on AWS RDS. I'm running into an issue causing 95% (not all) of the columns in each table to duplicate twice (for a total of three columns with the same name/type). The process runs and completes successfully with the duplication issue and it also doesn't generate any constraints even though they're set up from the MySQL side.

    Has this been fully tested on a MySQL db? Just want to make sure I'm doing everything right. Here's an example of the yaml file I'm using to run the process:

    # Connection properties
    connectionString: "mysql://username:password@tcp(database.identifier.us-region-1.rds.amazonaws.com:3306)/default-schema"
    
    # Define what tables should be used
    useAllTables: true
    
    # Additional flags
    showAllConstraints: true
    encloseWithMermaidBackticks: true
    outputFileName: "default-schema-mermerd.md"
    debug: true
    omitConstraintLabels: true
    

    There is a hyphen "-" in our schema name. Could that be causing a problem? The only odd thing I've noticed is that (because it's MySQL) we're specifying the schema in the connection string and then the CLI asks again for the schema once it connects to the db instance. That might just be a MySQL thing because I know Postgres is set up differently to have a DB and then have Schemas under each DB whereas MySQL considers schemas like Postgres does a database.

    Thanks!

Example golang using gin framework everything you need, i create this tutorial special for beginner.

Golang Gin Framework Fundamental Example golang using gin framework everything you need, i create this tutorial special for beginner. Feature Containe

Dec 16, 2022
Create a demo RESTful application using Golang

Instructions The goal of this exercise is to create a demo RESTful application using Golang. The Task In this task, we are building backend of an appl

Oct 30, 2021
Create a Protocol Buffers (Protobuf) plugin, which is executed with the protoc compileCreate a Protocol Buffers (Protobuf) plugin, which is executed with the protoc compile

Interview Assignment Overview You assignment is to create a Protocol Buffers (Protobuf) plugin, which is executed with the protoc compiler. In this ex

Nov 19, 2021
Create a short link

Shortlink using a GCP Cloud Run Serverless example Make a Dir: mkdir shortlink && cd shortlink Clone: git clone https://github.com/tonnytg/shortlink.

Nov 26, 2021
This application is a tool to rapidly create TFS tasks and synchronize them with wiki.

This application is a tool to rapidly create TFS tasks and synchronize them with wiki.

Jan 10, 2022
Give developers an easy way to create and integrate bank processing into their own software products
Give developers an easy way to create and integrate bank processing into their own software products

Community · Blog moov-io/bankcron Moov's mission is to give developers an easy way to create and integrate bank processing into their own software pro

Sep 27, 2022
poCo: portable Containers. Create statically linked, portable binaries from container images (daemonless)
poCo: portable Containers. Create statically linked, portable binaries from container images (daemonless)

poCo Containers -> Binaries Create statically linked, portable binaries from container images A simple, static golang bundler! poCo (portable-Containe

Oct 25, 2022
Using golang framework (Gin) to create a web-application

News feeder Using golang framework (Gin) to create a web-application. This simpl

Aug 22, 2022
ging is a tool for create gin web framework development templates

ging ging is a tool for create gin web framework development templates This tool is for the freshmen who want to learn golang and gin web framework, i

Jan 15, 2022
A new way to create web applications using go and sdf framework.

SDF GO A new way to create web applications using go and sdf framework Explore the docs » View Demo · Report Bug · Request Feature Table of Contents A

Sep 27, 2022
Create diagrams from the Kubernetes API with go-diagrams.
Create diagrams from the Kubernetes API with go-diagrams.

Kubernetes diagrams k8s-diagrams creates diagrams from your kubernetes clusters. You just have to provide a namespace (or not), and you get a picture

Dec 12, 2022
This package provides Go (golang) types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most famously used by app.diagrams.net, the new name of draw.io.

Go Draw - Golang MX This package provides types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most fa

Aug 30, 2022
Create beautiful system diagrams with Go
Create beautiful system diagrams with Go

Go-Diagrams Fast and easy application diagrams Go-Diagrams is a loose port of diagrams. Contents Features Usage Features Turn this: d, err := diagram.

Jan 7, 2023
RbacCustom - Create Tables Before executing the APIs

rbacCas Create Tables Before executing the APIs Members Table CREATE TABLE publi

Feb 8, 2022
Generate High Level Cloud Architecture diagrams using YAML syntax.
Generate High Level Cloud Architecture diagrams using YAML syntax.

A commandline tool that generate High Level microservice & serverless Architecture diagrams using a declarative syntax defined in a YAML file.

Dec 24, 2022
A command line tool to generate sequence diagrams
A command line tool to generate sequence diagrams

goseq - text based sequence diagrams A small command line utility used to generate UML sequence diagrams from a text-base definition file. Inspired by

Dec 22, 2022
Generate plantuml diagrams from go source files or directories
Generate plantuml diagrams from go source files or directories

go-plantuml go-plantuml generates plantuml diagrams from go source files or directories. Installation go get -u github.com/bykof/go-plantuml Please co

Jan 9, 2023
Generate plantuml diagrams from go source files or directories
Generate plantuml diagrams from go source files or directories

go-plantuml go-plantuml generates plantuml diagrams from go source files or directories. Installation go get -u github.com/bykof/go-plantuml Please co

Jan 1, 2023
A CLI for generating ER diagrams for Ent schema
A CLI for generating ER diagrams for Ent schema

enter A CLI for generating ER (entity-relationship) diagrams for Ent schema using mermaid.js.

Dec 18, 2022
Generate PlantUML diagrams from Chrome or Firefox network inspections

hoofli Generate PlantUML diagrams from Chrome or Firefox network inspections This tool reads browser HAR files stored on your local disk and transform

Nov 15, 2022