Sharing research on ER diagram automation in Rails environment

Introduction

There is a requirement to automate the ER diagram in business, and I would like to share the contents of the survey at that time as well.

Result of investigation

First of all, from the results of the survey, it was concluded that it is a little difficult to certify as a formal ER diagram because the number of tables and columns in the database used in business is quite large. Rather, it will display unnecessary tables and columns, so it is useless to output all of them. However, I feel that it is difficult to separate them now. However, there were some good things to check locally, so I decided to share it this time.

Premise

Since all methods use ** graphviz **, install ** graphviz ** on the OS with the following command.

$ brew install graphviz

Proposal 1 rails ERD (Gem)

At the personal development level, this is still easy to see, but when it comes to business use, the format is hard to see and I can only see the relationship between the tables.

https://github.com/voormedia/rails-erd

Gemfile


group :development, :test do
  gem 'rails-erd'
end
$ bundle exec erd

Proposal 2 Rail Roady (Gem)

This is also easy to see at the personal development level, and I thought it would be nice because it can be output by the model and the controller respectively, but when it is used for business, the format is also difficult to see.

https://github.com/preston/railroady

Gemfile


group :development, :test do
    gem 'railroady'
end
$ bundle exec rake diagram:all

Those who use the Rails engine are as follows.

$ bundle exec rake diagram:all_with_engines

Proposal 3 Output ER diagram using the export function of Sequel Pro

This might have been the easiest to see if you had a quick look at the entire table structure.

If you like suin's article below, you can go, so ... How to output ER diagram with Sequel Pro

Proposal 4 Use DBeaver

Perhaps this is the best way to look at foreign keys and relations for each table. If you look at the display part of the ER diagram in the following article, you can see that you can see the ER diagram like this. DBeaver usage memo

Finally

It was also interesting that there were surprisingly various methods like this, and that there were new discoveries and that there were strengths and weaknesses when actually looking at each method.

By the way, I personally use DBeaver. I hope it helps.

Recommended Posts

Sharing research on ER diagram automation in Rails environment
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Ruby on Rails Japanese-English support i18n
Ruby on Rails 6.0 environment construction memo
Rails on Docker environment construction procedure
[Rails 6] Customize Bootstrap in Rails + Bootstrap 5.0.0-alpha environment
Use docker in proxy environment on ubuntu 20.04.1
Ruby on Rails in Visual Studio Codespaces
Show Better Errors in Rails + Docker environment
Beginners create portfolio in Ruby on Rails
[Rails] Reset the database in the production environment
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
Just install Laravel8 on docker in PHP8 environment
(Basic authentication) environment variables in rails and Docker
[Rails] Run LINEBot in local environment using ngrok
rails tutorial About account activation in production environment
Recommendation of Service class in Ruby on Rails
Rails5.1 + puma SSL connection in local production environment
Rails new in Ruby on Rails ~ Memorandum until deployment 2
[Personal memo] Ruby on Rails environment construction (Windows)
500 Internal Server Error occurs in Rails production environment
Rails new in Ruby on Rails ~ Memorandum until deployment 1
[Ruby on Rails] Let's build an environment on mac
(Ruby on Rails6) Creating data in a table
Ruby on Rails development environment construction on M1 Mac
[Ruby on Rails] How to install Bootstrap in Rails
[Rails] How to use PostgreSQL in Vagrant environment