jenseng / hair_trigger

Happy database triggers for ActiveRecord
MIT License
773 stars 95 forks source link

Rails 6.0 - "Nothing to do" when running rake db:generate_trigger_migration #84

Open Owumaro opened 5 years ago

Owumaro commented 5 years ago

When I run rake db:generate_trigger_migration for my Rails 6.0 app I get "Nothing to do" even if I added triggers to a model.

This is tied to this issue : https://github.com/rails/rails/issues/37006

See https://github.com/ojab/hair_trigger/blob/rails-6/lib/hair_trigger.rb#L24 To get models, this gem runs

Rails.application.eager_load!
ActiveRecord::Base.descendants

However it is not enough in Rails 6.0, you have to run Zeitwerk::Loader.eager_load_all to load all models before running ActiveRecord::Base.descendants.

Not sure if this gem should adapt itself or wait for a fix in Rails.

jainbasil commented 4 years ago

I'm also facing the same issue using hair_trigger with Rails 6. Migrations are not getting generated.

pedantic-git commented 4 years ago

@jainbasil Me too. I have taken to going to the Rails console and issuing a variant of @Owumaro's note above:

Zeitwerk::Loader.eager_load_all
Rails.application.load_tasks
Rake::Task['db:generate_trigger_migration'].invoke

It would be great for this gem to get a fix so I can go back to just using the rake task!

pedrofurtado commented 4 years ago

Related to https://github.com/rails/rails/issues/37006

jenseng commented 3 years ago

Is this still an issue? Seems like a fix may have been merged to rails 6 stable here: https://github.com/rails/rails/commit/3285f3df7bc3a7a978428044b5458f1eed30b1a9

pedantic-git commented 3 years ago

@jenseng Confirmed I can now generate migrations with the rake task in Rails 6.0.3.5, so I think you're right it's been fixed upstream.