Drop database of Rails application from Ruby script, outside of application -


i need run 'rake db:drop' console command ruby script (outside of rails app). looks simple:

system("cd /my/path && rake db:drop") 

but problem i'm under rvm hell, , when i'm doing cd /my/path doesn't load correct gemset , environment, that's why result have

could not find activesupport-3.1.12 in of sources run `bundle install` install missing gems 

additionally, have open connections problem, rails application running.

how done? (my global task close existing connections database (we may have some, need drop running rails app database), drop it, , recreate again)

thank you!

to kill active connections, use in rake task. should take care of 1 problem.

task :kill_postgres_connections => :environment   db_name = "#{file.basename(rails.root)}_#{rails.env}"   sh = <<eof ps xa \   | grep postgres: \   | grep #{db_name} \   | grep -v grep \   | awk '{print $1}' \   | xargs kill eof   puts `#{sh}` end  task "db:drop" => :kill_postgres_connections 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -