2016-02-01 17:37:37 +01:00
|
|
|
namespace :dev do
|
2017-10-11 21:26:09 +02:00
|
|
|
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-11 21:26:09 +02:00
|
|
|
|
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)
|
2017-10-11 21:26:09 +02:00
|
|
|
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)
|
2017-10-18 10:48:35 +02:00
|
|
|
Rake::Task["db:test:prepare"].invoke
|
2017-10-11 21:26:09 +02:00
|
|
|
end
|
2017-10-09 18:17:40 +02:00
|
|
|
|
|
|
|
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
|