Created
February 3, 2014 15:33
-
-
Save adamdilek/8786007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :dev do | |
# Just run development env | |
# This code run insert seed and agency data | |
# A simple trick to over migration problem | |
task :setup => [:environment] do | |
raise 'Nah, You are at production' if Rails.env.production? | |
Rake::Task['dev:kill_postgres_connections'].execute | |
Rake::Task['db:drop'].execute | |
Rake::Task['db:create'].execute | |
Rake::Task['db:migrate'].execute | |
end | |
task :kill_postgres_connections => [:environment] do | |
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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment