I have the following 2 rake
tasks:
task :clone => :environment do |t, args|
Rake::Task["db:drop"].invoke
Rake::Task["db:create"].invoke
system "pg_restore -O -d database_name last_dump"
Rake::Task["db:migrate"].invoke
Rake::Task["db:test:prepare"].invoke
# Try to force the rails env to reload, but this doesn't solve the problem
Rake::Task["environment"].execute
Rake::Task["db:company_count"].invoke
end
task :company_count => :environment do
puts Company.count
end
When I run rake db:clone
the output the Company.count
is 0 indicating there are no Companies in the database, but when I run rake db:clone && rake db:company_count
the output is 2.
How do I get the correct Company.count
after loading the database in the first task?
The Company.count
is correct if I remove Rake::Task["db:test:prepare"].invoke
from the clone
task, but I'm not sure why