0

I have created database migration, and migrated data both on development and production servers. I would like to populate database from the application, if it is empty and avoid rake db:seed and other similar methods. I know that it could be done through rake db:seed, but since application is already deployed I would not like to pollute deploy.rb for capistrano, or do it manually on both development and production.

Is there any hook on database open or initialization of Active Record where I can do something like

if !Pages.first
  Pages.populate
end

I am aware of all recommended methods to populate database, but I would still prefer to do it from app.

Thanks

1 Answer 1

1

As you eluded to, this is not the best idea in the world, but maybe you could try using on of these approaches:

  1. An initializer that will get called each time the rails environment is loaded.
  2. Something in the config.after_initialize block. See http://guides.rubyonrails.org/configuring.html
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, nr. 2 works perfectly, meanwhile I found even simpler solution - define initdata method in model, and call it in another migration. This way on next cap deploy it goes to production server. Anyway I was hoping that there are hooks in ActiveRecord on database open, first access or simmilar...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.