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

Generate Mermaid Diagrams for Your Database #84

Open
1 of 2 tasks
nelsonic opened this issue Oct 10, 2022 · 30 comments
Open
1 of 2 tasks

Generate Mermaid Diagrams for Your Database #84

nelsonic opened this issue Oct 10, 2022 · 30 comments
Labels
discuss Share your constructive thoughts on how to make progress with this issue enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-3 Third priority. Considered "Nice to Have". Not urgent. T4h Time Estimate 4 Hours technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented Oct 10, 2022

https://dev.to/sualeh/how-to-generate-mermaid-diagrams-for-your-database-33bn 👀
Appears to require running a python script ... 💭
Really wish there was automatic SQL import that would generate valid Mermaid ... 🙏

This looks promising: https://github.com/KarnerTh/mermerd and under active development. 🤞

Todo

  • Make time to investigate / try this.
  • Ideally we could:
  1. Auto-generate the Mermaid for the Schema on GitHub CI after the Elixir/Phoenix tests are complete.
  2. Upload the resulting Mermaid either to GitHub via automated PR or S3 if that proves too difficult
  3. Have a static web page where anyone can inspect the latest ERD deployed for the App.
@nelsonic nelsonic added enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T4h Time Estimate 4 Hours technical A technical issue that requires understanding of the code, infrastructure or dependencies discuss Share your constructive thoughts on how to make progress with this issue labels Oct 10, 2022
@ndrean
Copy link

ndrean commented Oct 10, 2022

Isn't Ecto.ERD good enough for your usage?

@nelsonic
Copy link
Member Author

@ndrean great question. Probably. Thanks for the reminder. 🎉

@nelsonic nelsonic self-assigned this Oct 10, 2022
@nelsonic nelsonic added this to More ToDo ThanCanEver Be Done in Nelson's List via automation Oct 10, 2022
@ndrean
Copy link

ndrean commented Oct 10, 2022

exports to mermaid but I don't like these diagrams. Dot is ok.

@ndrean
Copy link

ndrean commented Oct 10, 2022

I made a "self reminder post" on this

@nelsonic
Copy link
Member Author

@ndrean great post. Thanks for making it and sharing. 🚀
I've been creating the ERDs manually using the GUI tool ... e.g: /mvp/BUILDIT.md#2-create-schemas
Knew there had to be a better way; plenty of people face this problem. 👍

@nelsonic nelsonic pinned this issue Oct 10, 2022
@ndrean
Copy link

ndrean commented Oct 11, 2022

I do this kind of post just for myself because I tend to forget so glad it is understandable. For your use case, it's just 2 lines in the terminal: mix ecto..gen.erd and dot ....

@ndrean
Copy link

ndrean commented Oct 11, 2022

In return, any guidance on your site for Changesets?

@nelsonic
Copy link
Member Author

Good question. I don't think we have anything yet. Do you have a specific question about them? 💭
I think all our use of changesets is super-basic and we haven't written a tutorial that focusses on them, yet. 🤔
But it highly likely the question will come up so if you have a specific issue you're facing. Please share. 🙏

@ndrean
Copy link

ndrean commented Oct 11, 2022

Well, a few problems 🤯 When I apply a changeset for an on-the-fly validation (phx-change) with a multiple input form, the error span position is difficult to position. But worse, I don't understand how this works when you then do a phx-submit with an invalidated form. I do something liike changeset.valid? ... true -> save, false -> return changeset. However, if I submit an invalid form, the first submit returns the error, but if I submit again twice an invalid form, then the button disappears... I am almost sure I am not clear at all

def handle_event("up_date", %{"new_event" => %{"event_date" => date}} = _params, socket) do
    changeset = NewEvent.changeset(%NewEvent{}, %{"event_date" => date})
    %{user_id: user_id, place: place} = socket.assigns

    case changeset.valid? do
      true ->
        :ok = async_create_event(%{...})
        {:noreply, socket}

      false ->
        {:error, changeset} = Ecto.Changeset.apply_action(changeset, :insert)
        # changeset = Map.put(changeset, :action, :insert)
        {:noreply, assign(socket, :changeset, changeset)}
    end
  end  

@ndrean
Copy link

ndrean commented Oct 11, 2022

https://github.com/ndrean/live_map/blob/main/lib/live_map_web/live/forms/new_event.ex is my repo, my first little Elixir app🔥

@ndrean
Copy link

ndrean commented Oct 11, 2022

First invalid submit:
Screenshot 2022-10-11 at 10 23 55

second submit..no more button!
Screenshot 2022-10-11 at 10 27 23

@nelsonic
Copy link
Member Author

@ndrean looks like a super interesting project. ⭐
Definitely add more context/docs to the README.md both for yourself and for others. 📝

@ndrean
Copy link

ndrean commented Oct 11, 2022

Humm, no tests, no writings... awful I know but I also have to learn how to write tests!! ..... I have some notes prepared indeed to explain and remember what I did😁, I will put it in the Readme, you are right. The best is to run the app! Right now, this "changeset" problem drives me mad😤

@nelsonic
Copy link
Member Author

Only an insanely curious and time-rich person will run an App that has an incomplete README.md. 💭
I'm curious, but time-poor so I need badges GitHub Workflow Status to reassure me that everything is working, ✅
before I spend any time running random projects I discover on the interwebs. 😜

Anyway ... going to try and use your recommended script to create an ERD now. 🤞

@nelsonic nelsonic moved this from More ToDo ThanCanEver Be Done to In progress in Nelson's List Oct 11, 2022
@ndrean
Copy link

ndrean commented Oct 11, 2022

Yes! this badges GitHub Workflow Status too!!! So many things to learn but that's the goal isn't it?

@ndrean
Copy link

ndrean commented Oct 11, 2022

Added an embryo of explanations/notes in the Readme🥳, then tests, then github flows

@ndrean
Copy link

ndrean commented Oct 11, 2022

Bug found / fixed !!! 🙏.

It stupidly put (as an experiment but hey why not) the attribute phx-disable-with: "loading..." in the form.

First invalid submit returns nicely:

Screenshot 2022-10-11 at 18 12 20

When I submit twice an invalid form, Phoenix decides to put phx-page-loading disabled and I am blocked:

Screenshot 2022-10-11 at 18 13 45

-> 🪳

Morality: get rid of phx-disable-with

@nelsonic
Copy link
Member Author

Instructions pertinent to the OP of this issue:

  1. Add the following line to the deps in your mix.exs:
{:ecto_erd, "~> 0.5", only: :dev},

See: https://github.com/fuelen/ecto_erd

  1. Run:
mix deps.get
  1. Generate the mermaid diagram with the following command:
mix ecto.gen.erd --output-path=ecto_erd.mmd

See: https://hexdocs.pm/ecto_erd/Mix.Tasks.Ecto.Gen.Erd.html for docs.

@nelsonic
Copy link
Member Author

erDiagram
  apikeys {
    integer id PK
    bytea client_secret
    bytea client_id
    integer person_id
    integer status
    integer app_id
    timestamp inserted_at
    timestamp updated_at
  }
  apps {
    integer id PK
    bytea desc
    timestamp end
    bytea name
    bytea url
    integer person_id
    integer status
    timestamp inserted_at
    timestamp updated_at
  }
  logs {
    integer id PK
    integer app_id
    varchar auth_provider
    bytea email
    varchar msg
    integer person_id
    bytea request_path
    integer status_id
    integer user_agent_id
    timestamp inserted_at
    timestamp updated_at
  }
  people_roles {
    integer id PK
    integer app_id
    integer person_id
    integer role_id
    integer granter_id
    timestamp revoked
    integer revoker_id
    timestamp inserted_at
    timestamp updated_at
  }
  permissions {
    integer id PK
    varchar desc
    varchar name
    integer person_id
    timestamp inserted_at
    timestamp updated_at
  }
  people {
    integer id PK
    varchar auth_provider
    bytea email
    bytea email_hash
    bytea familyName
    bytea givenName
    varchar locale
    bytea password_hash
    bytea picture
    bytea username
    bytea username_hash
    integer status
    integer tag
    integer key_id
    integer app_id
    integer github_id
    timestamp inserted_at
    timestamp updated_at
  }
  roles {
    integer id PK
    varchar desc
    varchar name
    integer person_id
    integer app_id
    timestamp inserted_at
    timestamp updated_at
  }
  sessions {
    integer id PK
    integer app_id
    varchar auth_provider
    timestamp end
    integer person_id
    integer user_agent_id
    timestamp inserted_at
    timestamp updated_at
  }
  status {
    integer id PK
    varchar text
    varchar desc
    integer person_id
    timestamp inserted_at
    timestamp updated_at
  }
  user_agents {
    integer id PK
    varchar name
    bytea ip_address
    bytea ip_address_hash
  }
  schema_migrations {
    integer version
    timestamp inserted_at
  }
  apps ||--|{ apikeys : ""
  apps ||--|{ people_roles : ""
  people ||--|{ people_roles : ""
  people ||--|{ status : ""
  roles ||--|{ people_roles : ""

@nelsonic
Copy link
Member Author

I was - perhaps naively - hoping that the resulting diagram would be reasonably optimised, but it's not.
And the default GitHub rendering means the font size is minuscule even fully zoomed in.

image

Need to re-assess this with fresh eyes in the morning. 💭

@nelsonic nelsonic moved this from In progress to Backlog (Prioritized) in Nelson's List Oct 11, 2022
@nelsonic nelsonic moved this from Backlog (Prioritized) to In progress in Nelson's List Oct 11, 2022
@nelsonic nelsonic moved this from In progress to Backlog (Prioritized) in Nelson's List Oct 11, 2022
@ndrean
Copy link

ndrean commented Oct 11, 2022

Can you make two pages? the 5 orphans and the other one with your triple joint table plus 2 tables 1<n. Authentication is hell!!

@nelsonic
Copy link
Member Author

Yeah, auth is unnecessarily complicated. We are trying to simplify it. ⏳
Our ONE Environment Variable™ approach in auth_plug is the best we've come up with so far. 💭

Need to fully document our initial implementation of auth so we can re-build it: dwyl/auth#207 🚧
Hence my desire to streamline - hopefully automate - the creation of ERDs. 🤞

@ndrean
Copy link

ndrean commented Oct 12, 2022

My two cents. What is the usage of the "apps" table where you declare an "owner" (I imagine) with its apikeys in this context? Did you implement an RBAC?

@nelsonic
Copy link
Member Author

@ndrean mega appreciate your feedback on auth, 👌
perhaps we need an issue in that repo instead of this one ... 💭

@ndrean
Copy link

ndrean commented Oct 13, 2022

Do you really want to manage passwords? Don't you think that a passwordless process with a magic link should be the way to go? and then just produce a JWT or a session header for authorisation?
Or also rely on social media credentials (they did the job for you to double-check the email).

@nelsonic
Copy link
Member Author

@ndrean we prioritise "social" (OAuth) login on https://auth.dwyl.com
image

Again, very much appreciate your feedback: https://github.com/dwyl/auth/issues 🙏

@ndrean
Copy link

ndrean commented Oct 13, 2022

The last identity login should just be passwordless I believe

@ndrean
Copy link

ndrean commented Oct 13, 2022

I also wanted to implement the Facebook login, but it seems hell to do server-side, whilst you also need HTTPS to use their snippet🤯

@nelsonic
Copy link
Member Author

For clarity: I despise passwords and they are widely regarded as inferior security.
But when you login to your GMail or other account, you still use a password ... 🙄
Encouraging people to click links in their email opens them to Phising ...
I know many apps do "Magic Links" and we know how to do them ... even Banking Apps! 🤦‍♂️
But I tend to avoid them in practice because non-technical users should not be encouraged to click links in their email.
The worst is links in SMS where Phishing is endemic!

Anyway ... back to the topic ERDs ... Going to stick with doing it manually for now as none of the auto-generation tools produce a good-looking image. 🙄 dwyl/auth#153 (comment)

image

@nelsonic nelsonic moved this from Backlog (Prioritized) to More ToDo ThanCanEver Be Done in Nelson's List Oct 13, 2022
@nelsonic nelsonic added priority-3 Third priority. Considered "Nice to Have". Not urgent. and removed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished labels Oct 13, 2022
@nelsonic nelsonic removed their assignment Oct 13, 2022
@ndrean
Copy link

ndrean commented Oct 13, 2022

You are absolutely right about phising... but the user is warned, it is not a surprise for him. The only experience I had with passwords was just horrible.
Looking at your schema. Quite dense 😬 . I understand rendering is not easy. But can't you separate concerns, I mean processes? Say authentication plug, then authorisation plug (you seem to have an RBAC southeast), then log plug northwest, then app credentials plug northeast?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Share your constructive thoughts on how to make progress with this issue enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-3 Third priority. Considered "Nice to Have". Not urgent. T4h Time Estimate 4 Hours technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
Nelson's List
  
More ToDo ThanCanEver Be Done
Development

No branches or pull requests

2 participants