File tree 2 files changed +57
-0
lines changed
2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ namespace :redis do
2
+ task :flush => :environment do
3
+ $redis. flushdb
4
+ end
5
+ end
You can’t perform that action at this time.
0 commit comments