Skip to content

Instantly share code, notes, and snippets.

@dich1
Last active January 14, 2019 07:49
Show Gist options
  • Save dich1/b8bae98c4a0e94279d6af41a34dbd473 to your computer and use it in GitHub Desktop.
Save dich1/b8bae98c4a0e94279d6af41a34dbd473 to your computer and use it in GitHub Desktop.
Railsでmigrate時にER図を自動生成する設定 ref: https://qiita.com/dich1/items/838918541e7612044a74
# ディストリビューションに合わせて
yum install graphviz
 or
apt-get install graphviz
rails db:migrate
group :development do
gem 'rails-erd'
end
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