Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Mermaid support #405

Merged
merged 4 commits into from
May 17, 2023
Merged

add Mermaid support #405

merged 4 commits into from
May 17, 2023

Conversation

ahmedash95
Copy link

@ahmedash95 ahmedash95 commented Feb 8, 2023

Regarding #226. This PR adds support for generating diagrams using Mermaid.

here is an example for Event Forms sample schema.

classDiagram
	direction RL
	class `ActiveRecord::InternalMetadata`
	`ActiveRecord::InternalMetadata` : +string value
	class `ActiveRecord::SchemaMigration`
	class `Event`
	`Event` : +boolean active
	`Event` : +string costs
	`Event` : +text description
	`Event` : +string duration
	`Event` : +text introduction
	`Event` : +text report
	`Event` : +string speaker
	`Event` : +string target_audience
	`Event` : +string title
	`Event` : +string tutors
	class `EventDate`
	`EventDate` : +string date
	`EventDate` : +text description
	`EventDate` : +date expiry_date
	`EventDate` : +string location
	class `Form`
	`Form` : +string name
	class `FormField`
	`FormField` : +string field_type
	`FormField` : +string label
	`FormField` : +boolean mandatory
	`FormField` : +string name
	class `FormFieldValue`
	`FormFieldValue` : +string key
	`FormFieldValue` : +string value
	class `Group`
	`Group` : +boolean active
	`Group` : +text description
	`Group` : +text email_message
	`Group` : +string email_receiver
	`Group` : +string email_subject
	`Group` : +string title
	`Group` : +string url_slug
	class `Organization`
	`Organization` : +string domain
	`Organization` : +text email_message
	`Organization` : +string email_receiver
	`Organization` : +string email_subject
	`Organization` : +string name
	`Organization` : +string phone
	`Organization` : +string signup_title
	`Organization` : +string subdomain
	`Organization` : +string website
	class `Signup`
	`Signup` : +boolean confirmed
	`Signup` : +string email
	`Signup` : +text serialized_fields
	class `Stylesheet`
	`Stylesheet` : +text content
	`Stylesheet` : +string name
	`Group` --> `Event`
	`Event` --> `EventDate`
	`EventDate` --> `Signup`
	`Organization` --> `Form`
	`Form` --> `Group`
	`Form` --> `FormField`
	`FormField` --> `FormFieldValue`
	`Organization` --> `Group`
	`Stylesheet` --> `Group`
	`Group` ..> `EventDate`
	`Organization` --> `Stylesheet`
	`Organization` ..> `Event`
Loading

Mermaid generator can be configured by passing generator=mermaid to the erd command or specifying the generator in configuration file to be mermaid. and it generates .mmd file.

rake erd generator=mermaid
  • Graphviz is not needed as a dependency if Mermaid is used.
  • I've tested mermaid generation against several rails projects and it works as expected.
  • The graphviz implementation includes different styles (Crowsfoot, Bachman, Uml). but none of them is supported in this PR.
  • The documentation will be added later once this PR is approved/merged

adding support for Mermaid (https://mermaid.js.org/)

Co-authored-by: Kyle Rames <kyle@rames.org>
@krames
Copy link
Contributor

krames commented Feb 8, 2023

I looked at the code climate error and I think given what the method is doing it is easier to read this way rather than breaking it up into individual methods. I will defer to your judgement though @ahmedash95.

Copy link

@kimbilida kimbilida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!! 🎩'd on a local project and it's working well.

@johnpaulashenfelter
Copy link

I would heartily endorse this. Worked great for me and avoids installing the what, two dozen dependencies that graphviz wants through homebrew.

Added to my :development group

gem 'rails-erd', git: 'git@github.com:ahmedash95/rails-erd.git', branch: 'support-mermaid'

and then ran it as asked.

@johnpaulashenfelter
Copy link

As an aside, I had been trying to do this with mermerd, a go app, but this implmentation works way better for my usecase since on MySQL i could not get it to generate the schema I wanted.

Its also worthwhile that this works without having to connect to the db in the first place, so maybe they are complementary? In any case 👍 would merge again 😄

attr_accessor :graph

setup do
self.graph = ["classDiagram"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking you needed an erDiagram for databases but I have not RTFMd

@johnpaulashenfelter
Copy link

:bump what can I do to help get this merged -- ❤️ using it.

@ahmedash95
Copy link
Author

Hey @johnpaulashenfelter, glad to see how useful it is. let's ping the maintainers to check this and hopefully get it merged

@ahmedash95
Copy link
Author

PING @kerrizor, can you check this PR, please?

@kerrizor
Copy link
Collaborator

Thanks, as always, for your patience with my being slow on updates and responses here! This is a great contribution, and I'm happy to merge. I've wanted to add mermaid support for quite some time, and this is a great first step; I especially appreciated making it an option, while maintaining graphviz as the default for now. I suspect that the direction to go for a next major release will be to flip this and make 🧜‍♀️ the default generator, but this gives us the ability to exercise this implementation and uncover any deeper problems before proceeding. Well done.

@kerrizor kerrizor merged commit 7c66258 into voormedia:master May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants