Postgres DDL to Mermaid Converter
Paste Postgres CREATE TABLE statements or pg_dump --schema-only
output and get a Mermaid ER diagram with every key marked and every relationship’s
cardinality worked out from your constraints — ready for a README or Mermaid Live.
Everything runs locally: your schema never leaves your browser.
Convert Postgres DDL to a Mermaid ER diagram
4 tables, 3 relationships, 1 enum.
Reading the example
orders.user_id is nullable, so a user is zero or one on the orders
side and the line is users |o..o{ orders. order_items.order_id
is NOT NULL and part of the item’s primary key, which makes it an identifying relationship:
orders ||--o{ order_items, drawn solid. profiles.user_id is
the whole primary key, so each user has at most one profile: users ||--o| profiles.
The CHECK constraint is dropped, the enum’s values move into the column comment, and
timestamp with time zone becomes timestamptz so Mermaid can
parse it.
CREATE TABLE to Mermaid ER diagram, without guessing
Most create table to mermaid er diagram scripts draw every foreign key as
one-to-many and stop there. The constraints in your DDL say more than that — whether a
parent is optional, whether the child is one-to-one, whether the key is identifying — and
this reads all of it. It is also a general SQL to Mermaid ERD converter
for plain CREATE TABLE syntax, but Postgres-specific pieces such as enums,
identity columns, COMMENT ON and ALTER TABLE ONLY are what it is
built around.
Postgres schema to Mermaid from a live database
To turn an existing Postgres schema to Mermaid, dump the structure and
paste the result: pg_dump --schema-only --no-owner mydb > schema.sql.
Functions, triggers, indexes, grants and sequences in the dump are ignored; tables, keys,
enums and column comments are read.
Where these rules come from
The relationship notation, the attribute-type rules and the PK/FK/UK markers are from Mermaid’s entity relationship diagram documentation, and the output was checked against Mermaid 11’s own parser. The type aliases are the ones listed in PostgreSQL’s data type documentation.