Last active
January 14, 2019 07:49
-
-
Save dich1/b8bae98c4a0e94279d6af41a34dbd473 to your computer and use it in GitHub Desktop.
Railsでmigrate時にER図を自動生成する設定 ref: https://qiita.com/dich1/items/838918541e7612044a74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ディストリビューションに合わせて | |
| yum install graphviz | |
| or | |
| apt-get install graphviz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rails db:migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| group :development do | |
| gem 'rails-erd' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative 'config/application' | |
| Rails.application.load_tasks | |
| # migrateのタスクをフックする | |
| Rake::Task['db:migrate'].enhance do | |
| if Rails.env.development? | |
| Rake::Task[:after_migrate].invoke | |
| end | |
| end | |
| # migrateの後のタスク | |
| task :after_migrate do | |
| Rake::Task[:create_erd].invoke | |
| end | |
| # ER図を作成 | |
| task :create_erd do | |
| # attributes=foreign_keys,primary_keys,timestamp (属性は主キー、外部キー、タイムスタンプを表示) | |
| # sort=false (カラム名をアルファベット順にしない) | |
| # filename=hage-erd (ファイル名) | |
| # filetype=png (ファイル拡張子) | |
| sh 'bin/rake erd attributes=foreign_keys,primary_keys,content,timestamp sort=false filename=hage-erd filetype=png' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment