voormedia / rails-erd

Generate Entity-Relationship Diagrams for Rails applications
http://voormedia.github.io/rails-erd/
MIT License
3.98k stars 362 forks source link

Detect ActiveRecord::* tables with hooking after 'db:migrate' #229

Open kikunantoka opened 7 years ago

kikunantoka commented 7 years ago

I want to use erd generating automatically. I wrote Rakefile as follows.

require_relative 'config/application'
Rails.application.load_tasks

Rake::Task['db:migrate'].enhance do
  Rake::Task['erd'].invoke
end

When I typed $ rails db:migrate, generated ER diagram has AcriveRecord::* tables such as ActiveRecord::InternalMetadata , ActiveRecord::SchemaMigration.

However, there is no AcriveRecord::* tables in generated ER diagram using following task.

require_relative 'config/application'
Rails.application.load_tasks

task :hoge do
  Rake::Task['db:migrate']
  Rake::Task['erd'].invoke
end

I resolved this problem setting .erdconfig as follows.

exclude: 'ActiveRecord::InternalMetadata, ActiveRecord::SchemaMigration'

I think this is not really problem but I report this problem.

kerrizor commented 7 years ago

Thanks for reporting!

I'd guess the reason has to do with the state of the in-memory cache of the accessible ActiveRecord objects with tables when inside enhance (which I haven't used before, so I learned something today!)

I don't know if we need to solve this or not, but if I were to solve it, I'd say mergeing those 2 tables to any user-supplied exclude options would be an easy way to solve it; I can't imagine anyone ever expecting those tables to be represented.

sfcgeorge commented 7 years ago

I don't see this problem. I was looking for a way to have ERD automatically updated on migrate (I thought this used to happen automatically, maybe I'm wrong) and found this issue. I copied the meat of the code into lib/tasks/erd.rake and it works great. No weird AR tables now. I'm on rails (5.0.1) and rails-erd (1.5.0) and inheriting my base model class as ApplicationRecord < ActiveRecord::Base.

Rake::Task["db:migrate"].enhance do
  Rake::Task["erd"].invoke
end