feat(er-diagram): export the schema as Mermaid or DBML#521
Open
gcapellib wants to merge 1 commit into
Open
Conversation
The ER diagram had no export at all. Add an Export button in the toolbar
opening a menu with two text formats, generated from the schema data
already in memory — no new dependency.
Mermaid erDiagram renders natively on GitHub, GitLab and most docs tools,
so the output can be pasted straight into a README. DBML keeps
relationships at column level and round-trips through dbdiagram.io and
dbml-to-sql, which Mermaid's entity-level edges cannot express.
Also widen the er-diagram window pattern in the capabilities file. The
window is created as 'er-diagram:{id}:{db}:{schema}' but only the literal
'er-diagram' was allowed, so every permission-gated call was rejected in
that window — dialog.save included. Other dynamic windows already use a
wildcard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The ER diagram had no export at all. This adds an Export button to the toolbar, opening a menu with two text formats generated from the schema data already in memory — no new dependency.
Why two formats
They cover different needs:
erDiagram) renders natively on GitHub, GitLab, Notion and most docs tools, so the output can be pasted straight into a README. Its relationships are entity-level, so the FK column only appears as a label.Ref: commandes.client_id > clients.id) and round-trips through dbdiagram.io anddbml-to-sql. Composite primary keys use anIndexesblock, as inline[pk]cannot express them.For reference, DBeaver's ER export is image/GraphML only. Its open request for Mermaid export (#36058) shows users falling back to exporting GraphML and hunting for converters that don't seem to exist.
Also fixed: permissions in the ER diagram window
src-tauri/capabilities/default.jsonallowed the literal window name"er-diagram", but the window is created aser-diagram:{connectionId}:{database}:{schema}(commands.rs:3874). Every permission-gated call was therefore rejected in that window:Changed to
"er-diagram*", matching the wildcard already used byjson-viewer-*,results-window-*andconnection-window-*. This is a pre-existing bug independent of the feature — any plugin call needing a permission in that window was blocked.Implementation
src/utils/schemaExport.ts, separate from the component so they can be unit-tested.allNodes/allEdgesrather than the rendered set, so the file stays complete even while a single table is focused.ContextMenucomponent.Encountered two children with the same key), which would otherwise produce repeated relationships. Worth a separate look, but the export is defensive about it.Testing
14 unit tests (Vitest) covering identifier sanitising, PK/FK markers, relationship direction, composite keys, de-duplication and empty tables.
Manually verified on MariaDB against a 15-table schema exercising self-references (
employes.manager_id,categories.parent_id), two FKs from one table to the same target (commandes.adresse_livraison_idandadresse_facturation_id), three composite PKs and a table referenced by five others. Both outputs render correctly in mermaid.live and dbdiagram.io.npm run typecheckclean.Possible follow-up
Image export (PNG/SVG) would cover a different need — pasting the diagram into a slide or a document. React Flow documents a path for it but it needs
html-to-imageas a new dependency, so I left it out rather than decide that here. Happy to add it in a follow-up if you'd want it.