Skip to content

Commit 8015f85

Browse files
committed
Added tasks copied from ASM to make downloading the production data easier
1 parent 091b7a6 commit 8015f85

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/tasks/db.rake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace :db do
2+
3+
task smash: %w(redis:flush db:schema:load db:test:prepare db:seed)
4+
5+
namespace :download do
6+
def db_dump_file
7+
`mkdir -p /home/vagrant/tmp`
8+
'/home/vagrant/tmp/coderwall-production.dump'
9+
end
10+
11+
desc 'Create a production database backup'
12+
task :generate do
13+
Bundler.with_clean_env do
14+
sh("heroku pgbackups:capture --expire --app #{ENV['HEROKU_APP_NAME']}")
15+
end
16+
end
17+
18+
desc 'Download latest database backup'
19+
task :latest do
20+
Bundler.with_clean_env do
21+
sh("curl `heroku pgbackups:url --app #{ENV['HEROKU_APP_NAME']}` -o #{db_dump_file}")
22+
end
23+
end
24+
25+
desc 'Load local database backup into dev'
26+
task load: :environment do
27+
raise 'local dump not found' unless File.exists?(db_dump_file)
28+
29+
puts 'Cleaning out local database tables'
30+
ActiveRecord::Base.connection.tables.each do |table|
31+
puts "Dropping #{table}"
32+
ActiveRecord::Base.connection.execute("DROP TABLE #{table};")
33+
end
34+
35+
puts 'Loading Production database locally'
36+
`pg_restore --verbose --clean --no-acl --no-owner -h localhost -d coderwall_development #{db_dump_file}`
37+
38+
puts '!!!!========= YOU MUST RESTART YOUR SERVER =========!!!!'
39+
end
40+
41+
task :clean do
42+
`rm #{db_dump_file}`
43+
end
44+
end
45+
46+
task restore: %w(db:download:generate db:download:latest db:download:load db:download:clean db:migrate)
47+
48+
desc 'ActiveRecord can you shut up for 30 minutes?'
49+
task mute: :environment do
50+
ActiveRecord::Base.logger = nil
51+
end
52+
end

lib/tasks/redis.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace :redis do
2+
task :flush => :environment do
3+
$redis.flushdb
4+
end
5+
end

0 commit comments

Comments
 (0)