KarnerTh / mermerd

Create Mermaid-Js ERD diagrams from existing tables
MIT License
460 stars 35 forks source link

Sort table names in mermaid file #34

Closed austin-artificial closed 1 year ago

austin-artificial commented 1 year ago

Sometimes the ordering of the tables changes in the mermaid file after a schema changes (at least with postgres). This can make diffs on that file a bit noisy.

I propose that the tables are alphabetically sorted. This could be done here: https://github.com/KarnerTh/mermerd/blob/d02edee5be037d52709a41ba5006103ef5bbf119/analyzer/analyzer.go#L58-L61 so that it isn't up to the individual database analyzers to worry about this.

If this isn't desirable default behaviour, maybe we could put it behind a --sortTables flag.

I'd be happy to have a go at implementing this if the approach is agreed upon.

KarnerTh commented 1 year ago

Reasonable proposal - I would sort it by default without an additional flag, because there is no downside in doing so

Ideally sorting is done on database level, but in this limited use case it is perfectly fine with me to do it programmatically (as you mentioned, it can be done independent of the database that is used and performance shouldn't be an issue here)

Feel free to implement it if you like - I will happily accept PRs :) Otherwise I'm happy to do it myself

KarnerTh commented 1 year ago

The change is available in version 0.8.0