Our database diagram is always out of date

Short answerStop redrawing the diagram by hand and take it from the database instead. DbSchema Pro keeps the design in a model file in Git and compares it with the live database, listing every difference and the SQL to close it. Free tools such as tbls and SchemaSpy rebuild docs and diagrams from the database. The free basics: keep the diagram next to the migrations and give it one owner.

01

Keep the design in DbSchema Pro and sync it with the database

DbSchema Pro saves the whole design, tables, foreign keys and diagrams, in one model file with the extension .dbs, and has Git built in, so the team shares one design with the history of every change. Schema Synchronization compares that model with the database, lists every difference and lets you choose for each one whether the model or the database wins. DbSchema then writes the SQL and shows it before it runs. Schema Documentation publishes the result as HTML5, PDF or Markdown with the diagram.

Good if several people change the schema and the diagram has to match what is deployed

Git Collaboration · Schema Synchronization · Schema Documentation · Editions and pricing

Tool
Cost€€
EffortMedium
HelpsThis week
02

Redraw it from the live database with DbSchema Community

DbSchema Community Edition is free for any use and connects to more than 100 SQL and NoSQL databases. Connect it, tick the schemas under Reverse Engineer the Database and press Import, and DbSchema draws the current tables and their relationships as an interactive ER diagram, with no table limit. Move to DbSchema Pro once you want to save the design to a file and keep it in sync.

Good if you need a correct picture of the schema today

Connect to a Database · ER diagram tool · Editions and pricing

Tool
CostFree
EffortLow
HelpsToday
03

Generate the docs with tbls and check them in CI

tbls is a free command-line tool that documents a database in Markdown and draws ER diagrams at the same time. Run tbls doc, commit the result, and add tbls diff or tbls lint to your CI. tbls diff shows the difference between the database schema and the committed document, so a schema change without a doc update gets noticed.

Good if your team already runs CI on every pull request

Skip if nobody can give CI a connection to a test database

GitHub

Tool
CostFree
EffortMedium
HelpsThis week
04

Publish HTML docs with SchemaSpy

SchemaSpy is a free Java tool that reads an existing database and generates HTML documentation with entity relationship diagrams. It runs as a single .jar file, so you can call it in a build job after each release and share the HTML with the team.

Good if people outside the dev team need to browse the schema

SchemaSpy

Tool
CostFree
EffortMedium
HelpsThis week
05

Re-import the schema into your drawing tool after each release

Export the current definitions, for example with pg_dump --schema-only on PostgreSQL, which writes the object definitions without data. In draw.io, open Arrange > Insert > Advanced > SQL, paste the SQL and click Insert. draw.io turns it into entities with their attributes, but you rearrange and connect them yourself each time.

Good if the team wants to keep its draw.io diagram

Skip if you release several times a week

PostgreSQL · draw.io

Do it yourself
CostFree
EffortLow
HelpsToday
06

Keep the diagram as Mermaid code next to the migrations

Write the diagram as a Mermaid erDiagram block in a Markdown file in the same repository as your migration files. GitHub renders Mermaid code blocks in Markdown, so the diagram shows up in the pull request. Update it in the same pull request as the migration, and reviewers see when one changes without the other.

Good if your schema changes go through pull requests

Skip if the schema has hundreds of tables

Mermaid · GitHub Docs

Do it yourself
CostFree
EffortLow
HelpsThis week
07

Give the diagram one owner

Name one person or team as owner of the migrations folder and the diagram file in a CODEOWNERS file. Code owners are automatically requested for review when someone opens a pull request that changes files they own. Add "diagram updated" to your change checklist.

Good if the diagram belongs to everyone and so to no one

GitHub Docs

Do it yourself
CostFree
EffortLow
HelpsToday

When it's bigger than a quick fix

Bring in a DBA or a data architect when the database and the diagram disagree and nobody can say which one is right, when production gets schema changes that are not in your migration files, or when several teams change the same schema.

PostgreSQL

Questions people ask

How do I keep an ER diagram up to date automatically?

Generate it from the database instead of drawing it. tbls and SchemaSpy read the live schema and write documentation with ER diagrams, and tbls diff can run in CI to catch a document that no longer matches.

Can draw.io create an ER diagram from SQL?

Yes. Arrange > Insert > Advanced > SQL turns pasted SQL into entities with their attributes. You then rearrange and connect them yourself.

Can I put an ER diagram in a GitHub README?

Yes. GitHub renders Mermaid code blocks in Markdown, and Mermaid has an erDiagram syntax for entities and relationships.

How do I get the current schema as SQL?

On PostgreSQL, pg_dump --schema-only writes the object definitions without the data.

Who should update the database diagram?

One named owner. With a CODEOWNERS entry, that owner is asked for review automatically on every pull request that touches the migrations or the diagram.

Sources

  1. DbSchema: Git Collaboration
  2. DbSchema: Schema Synchronization
  3. DbSchema: Schema Documentation
  4. DbSchema: Editions and pricing
  5. DbSchema: Connect to a Database
  6. DbSchema: ER diagram tool
  7. GitHub: k1LoW/tbls
  8. SchemaSpy: Database Documentation Built Easy
  9. PostgreSQL: pg_dump
  10. draw.io: Insert from SQL to create an ER diagram
  11. Mermaid: Entity Relationship Diagrams
  12. GitHub Docs: Creating diagrams
  13. GitHub Docs: About code owners
  14. PostgreSQL: Professional Services