ruby on rails - Run rake db:drop without failure if database doesn't exist -
this comment says:
db:drop can run without failure when db not exist
this need: need run db:drop without throwing exception or halt whole process if database doesn't exist, delete database if exists or nothing.
how can that? how can tell db:drop
not destroy life if database doesn't exist?
this code i'm experiencing problem (it help):
namespace :db task import: :environment rake::task["db:drop"].invoke # if database doesn't exist, whole import process terminates! rake::task["db:create"].invoke rake::task["db:migrate"].invoke database_config = rails.configuration.database_configuration[rails.env] system "psql --username=#{database_config['username']} #{database_config['database']} < postgresql.sql" end end
why can't go simple exception handling
namespace :db task import: :environment begin rake::task["db:drop"].invoke # if database doesn't exist, whole import process terminates! rake::task["db:create"].invoke rake::task["db:migrate"].invoke database_config = rails.configuration.database_configuration[rails.env] system "psql --username=#{database_config['username']} #{database_config['database']} < postgresql.sql" rescue exception => e p "the exception #{e.message}" end end end
Comments
Post a Comment