Reputation: 32233
I have a rails rake task and I want it to ignore what is in database.yml and use something else. How do I do this?
Upvotes: 0
Views: 2050
Reputation: 769
You can also have direct access to the database inside a rake task by using this format:
desc "Some task"
task SomeTask: :environment do
Author.all.each do |author|
... some code
end
end
Upvotes: 0
Reputation: 47568
You can use ActiveRecord::Base.establish_connection
to set up a database connection within a Rake task, as described in this SO question.
Or create a separate environment and add the database configuration to database.yml
. Then call the rake task with rake mytask RAILS_ENV=myenvironment
Upvotes: 2