Giter Site home page Giter Site logo

fuelen / ecto_erd Goto Github PK

View Code? Open in Web Editor NEW
206.0 6.0 11.0 66.28 MB

A mix task for generating Entity Relationship Diagram from Ecto schemas available in your project.

License: Apache License 2.0

Elixir 100.00%
ecto erd elixir uml dbml graphviz mermaid plantuml

ecto_erd's People

Contributors

brainlid avatar dependabot[bot] avatar dreigada avatar fuelen avatar jaimeiniesta avatar jjl avatar kianmeng avatar mstibbard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ecto_erd's Issues

How to exclude some schemas?

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

Support Embeds in Mermaid

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.

Grouping mechanism to generate multiple smaller diagrams

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?

Is it possible to pretty-print the Graphviz / dot output (including HTML inside)?

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:

Errors when running inside an umbrella application

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.

Include database indexes in the ERD

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 ๐Ÿ™

Examples generator compilation error

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.

missing composite indexes in dbml

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?

Ecto.Enum types not supported

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:

ecto_erd_enum

Instead, I would expect a shorter version of the enumerated type, including just the list of allowed values.

task crashes when run

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 SpecialUsers 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.

Document and improve ExDoc usage

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.