Hexa's Blog

Generate entity relationship based on model, Ruby on rails

07/08/2015 Ruby on Rails 4

During this time, I am in an internship program. There is a big concern, I have to work with a very big project, and there is no documentation. The number of tables in project’s database is more than 20, still no documentation.

A big nightmare for an intern one. It’s important to make an entity relationship diagram, at least with a hope that I can get cope easily with the project.

Game on!, There is a gem named erd - url

Setup and Installation

  • Install graphviz (fedora)
sudo dnf install -y graphviz
  • Add gem erd to gem file
group :development do
  gem "rails-erd"
end
  • Install bundle
bundle install

Configuration

Configuration file will be loaded at ~/.erdconfig or ...project_rails/.erdconfig, file config in the root of project will take higher priority than in the home directory.

attributes:
  - content
  - foreign_key
  - inheritance
disconnected: true
filename: erd
filetype: pdf
indirect: true
inheritance: false
markup: true
notation: simple
orientation: horizontal
polymorphism: false
sort: true
warn: true
title: sample title
exclude: null
prepend_primary: false

Generating entity diagram file

Entity diagram will be generated in the root directory of project.

bundle exec erd