SchemaRD

Overview

SchemaRD is a Entity Relationship Diagram Viewer for schema.rb which is used on Ruby On Rails. You can browse Entity Relationship Diagram of your schema.rb, on your WebBrowser.

How To Use

Install:

 $ gem install schemard

And run:

 $ schemard

And browse http://localhost:10080

How To Edit ERD

Edit Layout

In the ERD generated by default, the tables are laid out at random.
The figure below is the table schema which has generated from schema.rb of the Ruby On Rails Tutorial( https://www.railstutorial.org/ ).

You can adjust the position by checking "Edit table position" at the top left of the figure,
And dragging the table.

Add Relation

In the ERD generated by default, there is no relation information between tables.
To add a relation to the ERD, You need to create relation information and load it.
There are several ways to give a relation information.

This section explains how to add relation information based on model information of Rails application. Just as before, we will explain the procedure with the source code of Ruby On Rails Tutorial.

  1. Extract relation information with the following command. In this example, it outputs to db/relatoin.metadata.

    $ cd <Rails.root.dir>
    $ schemard gen-relation > db/relation.metadata
    
  2. The following contents are output to db/relatoin.metadata.

    ---
    tables:
    users:
    has_many:
    - microposts
    - relationships
    - relationships
    relationships:
    belongs_to:
    - users
    - users
    microposts:
    belongs_to:
    - users
    
  3. To load the extracted relationship information, execute with the following command option.

    $ schemard -f db/relation.metadata
    
  4. When accessing http://localhost:10080 in the Web browser, relations are added to the ERD.

Localization

Options

The following command line options can be specified.

Sub Command

The following sub-commands can be specified.

Configuration

Instead of specifying it with command line options, you can specify options in the configuration file.
Place the configuration file as .schemard.config in theschemard command execution directory. The following entries can be specified.