Convert

Convert a SQL schema into an ER diagram.

Foreign keys already encode the relationships and their cardinality. The diagram renders what the schema is enforcing anyway.

Download for macOS
v0.1.33 · .dmg · Apple Silicon & Intel
Signed & notarized by Apple · opens without a Gatekeeper warning
sha256 698955a0187bc039f4c74f5d05a9f10fbb27376a45788a0a241d1326b73873c7
Download for Windows instead
$curl -fsSL https://lucidtrain.com/install.sh | sh

Read from constraints, not guessed

A foreign key gives the relationship and its direction; a unique constraint on that key gives one-to-one rather than one-to-many; NOT NULL gives mandatory rather than optional. All of that is stated in the DDL, so the resulting cardinality is read rather than inferred, which is the difference between a diagram you trust and one you check.

Join tables become relationships

A table whose primary key is composed entirely of foreign keys is a join table. Drawing it as an entity produces a picture of your storage rather than your model, so it is recognised and drawn as a single many-to-many relationship instead. That one transformation is most of what makes a generated ER diagram match the model in your head.

Migrations work too

Most application repositories hold migrations rather than a checked-in schema, so the current shape is reconstructed by applying them in order. That works and takes longer on a long history, which is a decent argument for keeping a generated schema dump in the repository regardless.

Fidelity

Comes throughDoes not
TablesEvery table as an entity
Columns and typesYesVendor-specific types are approximated
Foreign keysRelationships with direction
CardinalityRead from unique and null constraints
Join tablesCollapsed into many-to-many
Implicit relationshipsA column with no constraint is invisible
Check constraintsAs notesNot as diagram semantics
Triggers and proceduresNot represented

The prompt

shell
$ Read the SQL schema here and draw an entity relationship diagram with cardinality marked and join tables collapsed.
FAQ

Questions

Does it connect to my database?

No. It reads DDL or migration files, so it needs no credentials and works against databases you cannot reach.

Which dialects work?

The common ones. It reads and reasons about DDL rather than parsing a specific dialect, so vendor extensions may be summarised rather than represented exactly.

Crow's foot notation?

Yes, since that is what engineering teams use in practice.

Related