如何从rake任务中查明数据库是否存在?
也就是说,我想做类似的事情:
task :drop_and_create => :environment do
Rails.env = "development"
if (db_exists?)
Rake::Task["db:drop"].invoke
end
Rake::Task["db:create"].invoke
#more stuff...
end
我该如何编写db_exists?条件?
答案 0 :(得分:1)
如何做一个开始/救援:
task :drop_and_create => :environment do
Rails.env = "development"
if (db_exists?)
begin
Rake::Task["db:drop"].invoke
rescue Exception => e
logger.debug("Error:#{e}")
Rake::Task["db:create"].invoke
#more stuff...
end
答案 1 :(得分:0)
task :drop_and_create => :environment do
Rails.env = "development"
Rake::Task["db:reset"].invoke
#more stuff...
end