fuelen / ecto_erd Goto Github PK
View Code? Open in Web Editor NEWA mix task for generating Entity Relationship Diagram from Ecto schemas available in your project.
License: Apache License 2.0
A mix task for generating Entity Relationship Diagram from Ecto schemas available in your project.
License: Apache License 2.0
Hi, Can some schema be excluded from generated ERD? There are some schemas that don't have tables, and I don't want to include this schema to generate ERD
Hi @fuelen and thank you for this lovely library.
I noticed that embedded schemas are not supported when the output document is set to Mermaid. Ecto.ERD.Document.Mermaid.schemaless?/0
returns true which instructs Graph.new/2
to graph associations but not embeds. What's blocking embeds support in Mermaid? I'd be happy to contribute a PR to add support.
After a project reaches a certain size the diagram starts to become so large it loses usefulness. What if we could optionally group schemas and then generate one diagram per group. Schemas can appear in zero or more groups. A simple solution might be something like defining a function in each schema to define the groups it belongs to:
def erd_groups(), do: [:project, :accounting]
Now this schema would make an appearance in the project
and accounting
diagrams. It's a little bit of configuration built right into the schemas that makes the diagrams a whole lot more readable.
I don't think it HAS to be built into the code, but I think it helps people remember to update/add it when they add a new schema. But I think it would be ok if the configuration was external to the schema. Keeping it in .ecto_erd.exs
is also an acceptable option. Or maybe implementing a tag?
Usecase: I have a Github Action which runs ecto_erd
on each merged PR.
That way I can see clear diffs in ecto schemas and whether this PR changed schemas at all.
It's easy to pretty-print Graphviz DSL, but unfortunatelly the HTML inside is still one big unformulated blob.
Two ways to pretty-print Graphviz:
nop http://myfile.dot
(https://graphviz.org/pdf/nop.1.pdf)dot -Tcanon http://myfile.dot
(https://graphviz.org/docs/outputs/canon/)PlantUML is not the best ERD diagramming tool [1], but it's the best Diagrams-as-Code tool overall, and also used in C4-PlantUML [2,3] Software Documentation methodology.
[1] https://plantuml.com/ie-diagram
[2] https://github.com/plantuml-stdlib/C4-PlantUML
[3] https://engineering.linecorp.com/en/blog/diagramming-software-architecture-using-c4-model-and-c4-plantuml/
I have a "core" app with the majority of my Ecto schemas. Then I have a "web" app that depends on "core". The "web" app also introduces some embedded Ecto schemas that are used for form validation but not tied to a DB table.
When I run it on this project, I get the following error:
$ mix ecto.gen.erd
** (RuntimeError) Unable to detect `:otp_app`, please specify it explicitly
(ecto_erd 0.5.0) lib/mix/tasks/ecto.gen.erd.ex:143: Mix.Tasks.Ecto.Gen.Erd.run/1
(mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
(mix 1.13.4) lib/mix/cli.ex:84: Mix.CLI.run_task/2
I tested it on a non-umbrella application (standard Phoenix app) and it worked.
I'm using the Graphviz Interactive Preview VS Code extension to visualize DOT files.
It would be great to be able to configure the styles for the generated diagrams, in terms of colors, border thickness, etc. By now I think it's only possible to change the font.
Hi there, thanks for the great work on this library!
Apart from supporting Mermaid generation which from my understanding it's currently work in progress, I would like to also make a request to support the inclusion of database indexes in the ERD ๐
Thanks for the package, it helps a lot creating beautiful ERD diagrams, I was missing those these days :)
Using ecto_erd
as a dependency has raised a compilation error in my setup.
Error while loading project :ecto_erd at /home/pascal/elixir/realworld/elixir-phoenix-realworld-example-app/deps/ecto_erd
** (Code.LoadError) could not load /home/pascal/elixir/realworld/elixir-phoenix-realworld-example-app/deps/ecto_erd/examples_generator.exs
(elixir 1.12.1) lib/code.ex:1806: Code.find_file/2
(elixir 1.12.1) lib/code.ex:1502: Code.compile_file/2
/home/pascal/elixir/realworld/elixir-phoenix-realworld-example-app/deps/ecto_erd/mix.exs:1: (file)
(elixir 1.12.1) lib/code.ex:1502: Code.compile_file/2
It appears that ExampleGenerator
is not available for compilation here.
Maybe a workaround would be to compile the file at runtime while generating the docs as the module is needed only for documentation generation.
I believe you generate everything from the schemas, ERDs and .dbml, not from the migrations. Given that an ERD doesn't display composite indexes but only pK, the ERDs are fine. However, composite indexes are declared in the migrations so the generated .dbml can't be converted into SQL to run a migration since indexes are missing. No way to overcome this programmatically?
Some of our models have fields of Ecto.Enum type.
When I generate a graph for them, the description for the type is too long, which leads to a very wide box for the entity:
Instead, I would expect a shorter version of the enumerated type, including just the list of allowed values.
I just installed this library and tried to run mix ecto.gen.erd
. It immediately crashed with this error:
** (UndefinedFunctionError) function SpecialUser.__schema__/1 is undefined (module SpecialUser is not available)
SpecialUser.__schema__(:source)
(ecto_erd 0.4.0) lib/ecto/erd/graph.ex:134: Ecto.ERD.Graph.from_relation_struct/1
(elixir 1.13.0-rc.0) lib/enum.ex:4076: Enum.flat_map_list/2
(ecto_erd 0.4.0) lib/ecto/erd/graph.ex:79: Ecto.ERD.Graph.components/2
(elixir 1.13.0-rc.0) lib/enum.ex:4076: Enum.flat_map_list/2
(elixir 1.13.0-rc.0) lib/enum.ex:4077: Enum.flat_map_list/2
(ecto_erd 0.4.0) lib/ecto/erd/graph.ex:9: Ecto.ERD.Graph.new/2
(ecto_erd 0.4.0) lib/mix/tasks/ecto.gen.erd.ex:138: Mix.Tasks.Ecto.Gen.Erd.run/
I am able to create SpecialUser
s in my app when I am using it and my app works fine in this regard, so I am not sure why this library is complaining.
First off, this project is super awesome! I love being able to have always up to date mermaid diagrams for my Ecto schemas.
I am currently using this library to generate mermaid diagrams in ex_doc. I think this usage is pretty common, but it's not documented and the API is a little verbose.
I can get mermaid diagrams outputted like so:
@moduledoc """
This is information about our `ATcms.Account` context.
#{ATcms.Account.UserSchema |> Code.ensure_loaded!() |> then(fn _ -> "" end)}
` ` `mermaid
#{Ecto.ERD.Document.render([ATcms.Account.UserSchema], ".mmd", &Function.identity/1, [])}
` ` `
"""
We should document this use case so other people can enjoy the fun! Secondly, it would be awesome to clean up this code and make it easier to use. Something like Ecto.ERD.render([ATcms.Account.UserSchema], ".mmd")
that would ensure the code is loaded and render out the modules to mermaid.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.