demarches-normaliennes/lib/tasks/dev.rake

33 lines
926 B
Ruby
Raw Normal View History

2016-02-01 17:37:37 +01:00
namespace :dev do
def run_and_stop_if_error(cmd)
sh cmd do |ok, res|
if !ok
abort "#{cmd} failed with result : #{res.exitstatus}"
end
end
end
task :import_db do
filename = "tps_prod_#{1.day.ago.strftime("%d-%m-%Y")}.sql"
local_file = "/tmp/#{filename}"
2018-05-29 16:52:30 +02:00
if !File.exist?(local_file)
2018-08-24 17:37:58 +02:00
run_and_stop_if_error "scp -C db1:/data/backup/#{filename} #{local_file}"
2018-05-29 16:52:30 +02:00
end
2017-10-19 16:15:34 +02:00
dev_env_param = "RAILS_ENV=development"
Rake::Task["db:drop"].invoke(dev_env_param)
Rake::Task["db:create"].invoke(dev_env_param)
run_and_stop_if_error "psql tps_development -f #{local_file}"
2017-10-19 16:15:34 +02:00
Rake::Task["db:migrate"].invoke(dev_env_param)
Rake::Task["db:environment:set"].invoke(dev_env_param)
Rake::Task["db:test:prepare"].invoke
end
task :console do
exec("ssh tps@sgmap_production1 -t 'source /etc/profile && cd current && bundle exec rails c production'")
end
2016-02-01 17:37:37 +01:00
end