Skip to content

Instantly share code, notes, and snippets.

@adamdilek
Created February 3, 2014 15:33
Show Gist options
  • Save adamdilek/8786007 to your computer and use it in GitHub Desktop.
Save adamdilek/8786007 to your computer and use it in GitHub Desktop.
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