1
2

More than 3 years have passed since last update.

rails-erdで指定したテーブルのみでER図を描く方法

Posted at

概要

  • railsアプリでER図を自動生成する際に利用するrails-erd
  • 一部のテーブルのみだけでER図を作りたい場合の解決方法を記載する

背景

  • サービスが拡大してテーブル構成がかなり複雑になってしまい、ER図をそのまま出力すると何が何やらの状態になってしまった
  • 一部のテーブルの関係性のみを可視化してわかりやすい形で出力したかったため、調査

方法

.erdconfigを使う

  • Rails ERD - Configuration
  • 抜粋

    Rails ERD has the ability to be configured via the command line or through the use of a YAML file with configuration options set. It will look for this file first at ~/.erdconfig and then ./.erdconfig (which will override any settings in ~/.erdconfig). The format of the file is as follows (shown here with the default settings used if no .erdconfig is found). More information on customization options can be found in Rails ERD's project documentation.

  • railsアプリのリポジトリルートに.erdconfigを配置(~/.erdconfigでもいいけど、こんな使い方する人はいなそう)

  • 以下のような内容を記述

  only:
    - Product
    - Order
    - Customer
  • あとはbin/bundle exec erdなどど通常のコマンドを打てばよい

コマンドラインオプションで指定

  • Rails ERD – Customisation options
  • 以下のようにコマンドを実行

    bin/bundle exec erd --only="Product,Order,Customer"
    
  • 少数のテーブルで軽く確認してみたい程度ならこちらの方が使い勝手がよさそう

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2