Skip to content

Instantly share code, notes, and snippets.

@justin808
Created March 10, 2014 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justin808/9461522 to your computer and use it in GitHub Desktop.
Save justin808/9461522 to your computer and use it in GitHub Desktop.
def run_command_raise_if_error(command)
puts "Executing: #{command}"
result = %x[#{command}]
raise "rake task failed..........\n#{result}" if result.include?('rake aborted!')
end
def run_rake_command_raise_if_error(command)
run_command_raise_if_error("bundle exec rake #{command}")
end
namespace :db do
desc "Migrate DBs for envs test, ci, development. Then setup parallel."
task migrate_all: :environment do |t, args|
unless Rails.env.development?
raise "Can only run under development environment, but specified env was #{Rails.env}"
end
envs = %W(test ci development)
envs.each do |env|
run_rake_command_raise_if_error("RAILS_ENV=#{env} db:migrate")
end
run_rake_command_raise_if_error("parallel:create")
run_rake_command_raise_if_error("parallel:prepare")
run_rake_command_raise_if_error("parallel:rake[db:globals]")
run_command_raise_if_error("annotate -e \[tests\] -i")
end
desc "Update seed data in all test/dev databases"
task seed_all: :environment do |t, args|
unless Rails.env.development?
raise "Can only run under development environment, but specified env was #{Rails.env}"
end
envs = %W(test ci development)
envs.each do |env|
run_rake_command_raise_if_error("RAILS_ENV=#{env} db:seed")
end
run_rake_command_raise_if_error("parallel:rake[db:seed]")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment