effective_developer 0.4.14 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/effective_developer/version.rb +1 -1
- data/lib/tasks/pg_pull.rake +77 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0deae13cd4fb9d39c7108dbe297cbccce12e308dc8510f4f974c634a7d4045ee
|
4
|
+
data.tar.gz: 575191ece3ae021c25de70db77066cc0893cd7713707a63f1b700586c1a4b547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 103153bf5fe52387af807cb90b2855f17bfc490af84e2f1b7dcb058deac2b1e1901c5feb04a00119f66ad51db9363f44ad2224d346c570a251711f45143742c1
|
7
|
+
data.tar.gz: b9b6041460328adad3dc4910f0548171a35fd89a1b518d8a515f18740f8238f6db62629a8ef5d7530babe3677799d409f44129a86651a89af7b9d8edca4a3094
|
data/lib/tasks/pg_pull.rake
CHANGED
@@ -1,29 +1,65 @@
|
|
1
1
|
namespace :pg do
|
2
|
-
# Creates a new backup on
|
2
|
+
# Creates a new backup on remote server, downloads that backup to latest.dump, and then calls pg:load
|
3
3
|
#
|
4
4
|
# bundle exec rake pg:pull
|
5
5
|
# bundle exec rake pg:pull[staging]
|
6
|
-
|
6
|
+
# bundle exec rake pg:pull[158.204.33.124]
|
7
|
+
desc 'Creates a new backup on remote server and downloads it to latest.dump'
|
7
8
|
task :pull, [:remote] => :environment do |t, args|
|
8
|
-
args.with_defaults(:remote => 'heroku')
|
9
9
|
|
10
|
-
|
10
|
+
# Heroku mode
|
11
|
+
if `git remote -v | grep heroku`.length > 0
|
12
|
+
args.with_defaults(remote: 'heroku')
|
11
13
|
|
12
|
-
|
14
|
+
puts "=== Pulling remote '#{args.remote}' database into latest.dump"
|
15
|
+
|
16
|
+
# Create a backup on heroku
|
13
17
|
unless system("heroku pg:backups:capture --remote #{args.remote}")
|
14
|
-
|
15
|
-
|
18
|
+
abort("Error capturing heroku backup")
|
19
|
+
end
|
20
|
+
|
21
|
+
# Download it to local
|
22
|
+
unless system("curl -o latest.dump `heroku pg:backups:public-url --remote #{args.remote}`")
|
23
|
+
abort("Error downloading database")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Load it
|
27
|
+
Rake::Task['pg:load'].invoke
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
# Hatchbox mode
|
32
|
+
if (ENV['HATCHBOX_IP'] || args[:remote]).count('.') == 3
|
33
|
+
args.with_defaults(
|
34
|
+
remote: ENV.fetch('HATCHBOX_IP'),
|
35
|
+
app: ENV['HATCHBOX_APP'] || `pwd`.split('/').last.chomp,
|
36
|
+
user: ENV['HATCHBOX_USER'] || 'deploy'
|
37
|
+
)
|
38
|
+
|
39
|
+
puts "=== Pulling hatchbox '#{args.remote}' #{args.app} database into latest.dump"
|
40
|
+
|
41
|
+
# SSH into hatchbox and call rake pg:save there to create latest.dump
|
42
|
+
unless(result = `ssh #{args.user}@#{args.remote} << EOF
|
43
|
+
cd ~/#{args.app}/current/
|
44
|
+
bundle exec rake pg:save[latest.dump]
|
45
|
+
`).include?('Saving database completed') # The output of pg:save down below
|
46
|
+
puts("Error calling ssh #{args.user}@#{args.remote} and running rake pg:save on hatchbox from ~/#{args.app}/current/")
|
47
|
+
abort(result)
|
16
48
|
end
|
17
49
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
puts "Error downloading database"
|
22
|
-
exit
|
50
|
+
# SCP to copy the hatchkbox latest.dump to local
|
51
|
+
unless system("scp #{args.user}@#{args.remote}:~/#{args.app}/current/latest.dump ./")
|
52
|
+
abort("Error downloading database")
|
23
53
|
end
|
54
|
+
|
55
|
+
# Load it
|
56
|
+
Rake::Task['pg:load'].invoke
|
57
|
+
exit
|
24
58
|
end
|
25
59
|
|
26
|
-
|
60
|
+
puts "Unable to find pg:pull provider."
|
61
|
+
puts "Please add a heroku git remote or a HATCHBOX_IP environment variable and try again"
|
62
|
+
abort
|
27
63
|
end
|
28
64
|
|
29
65
|
# Drops and re-creates the local database then initializes database with latest.dump
|
@@ -33,9 +69,11 @@ namespace :pg do
|
|
33
69
|
desc 'Loads a postgresql .dump file into the development database (latest.dump by default)'
|
34
70
|
task :load, [:file_name] => :environment do |t, args|
|
35
71
|
args.with_defaults(:file_name => 'latest.dump')
|
36
|
-
db = ActiveRecord::Base.configurations[Rails.env]
|
37
72
|
|
38
|
-
|
73
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
74
|
+
db = { username: (config['username'] || `whoami`), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
|
75
|
+
|
76
|
+
puts "=== Loading #{args.file_name} into local '#{db[:database]}' database"
|
39
77
|
|
40
78
|
# bin/rails db:environment:set RAILS_ENV=development
|
41
79
|
if Rails.env != 'production'
|
@@ -45,10 +83,10 @@ namespace :pg do
|
|
45
83
|
Rake::Task['db:drop'].invoke
|
46
84
|
Rake::Task['db:create'].invoke
|
47
85
|
|
48
|
-
if system("pg_restore --no-acl --no-owner --clean --if-exists -h
|
86
|
+
if system("export PGPASSWORD=#{db[:password]}; pg_restore --no-acl --no-owner --clean --if-exists -h #{db[:host]} -U #{db[:username]} -d #{db[:database]} #{args.file_name}")
|
49
87
|
puts "Loading database completed"
|
50
88
|
else
|
51
|
-
|
89
|
+
abort "Error loading database"
|
52
90
|
end
|
53
91
|
end
|
54
92
|
|
@@ -57,14 +95,23 @@ namespace :pg do
|
|
57
95
|
desc 'Saves the development database to a postgresql .dump file (latest.dump by default)'
|
58
96
|
task :save, [:file_name] => :environment do |t, args|
|
59
97
|
args.with_defaults(:file_name => 'latest.dump')
|
60
|
-
db = ActiveRecord::Base.configurations[Rails.env]
|
61
98
|
|
62
|
-
|
99
|
+
db = if ENV['DATABASE_URL'].to_s.length > 0
|
100
|
+
uri = URI.parse(ENV['DATABASE_URL']) rescue nil
|
101
|
+
abort("Invalid DATABASE_URL") unless uri.present?
|
63
102
|
|
64
|
-
|
103
|
+
{ username: uri.user, password: uri.password, host: uri.host, port: (uri.port || 5432), database: uri.path.sub('/', '') }
|
104
|
+
else
|
105
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
106
|
+
{ username: (config['username'] || `whoami`.chomp), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
|
107
|
+
end
|
108
|
+
|
109
|
+
puts "=== Saving local '#{db[:database]}' database to #{args.file_name}"
|
110
|
+
|
111
|
+
if system("export PGPASSWORD=#{db[:password]}; pg_dump -Fc --no-acl --no-owner -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} #{db[:database]} > #{args.file_name}")
|
65
112
|
puts "Saving database completed"
|
66
113
|
else
|
67
|
-
|
114
|
+
abort "Error saving database"
|
68
115
|
end
|
69
116
|
end
|
70
117
|
|
@@ -77,20 +124,17 @@ namespace :pg do
|
|
77
124
|
|
78
125
|
Bundler.with_clean_env do
|
79
126
|
unless system("heroku pg:backups:capture --remote #{args.source_remote}")
|
80
|
-
|
81
|
-
exit
|
127
|
+
abort "Error capturing heroku backup"
|
82
128
|
end
|
83
129
|
|
84
130
|
url = (`heroku pg:backups:public-url --remote #{args.source_remote}`).chomp
|
85
131
|
|
86
132
|
unless (url || '').length > 0
|
87
|
-
|
88
|
-
exit
|
133
|
+
abort "Error reading public-url from remote #{args.source_remote}"
|
89
134
|
end
|
90
135
|
|
91
136
|
unless system("heroku pg:backups:restore '#{url}' DATABASE_URL --remote #{args.target_remote}")
|
92
|
-
|
93
|
-
exit
|
137
|
+
abort "Error cloning heroku backup"
|
94
138
|
end
|
95
139
|
end
|
96
140
|
|
@@ -102,7 +146,7 @@ namespace :pg do
|
|
102
146
|
args.with_defaults(:remote => 'heroku')
|
103
147
|
|
104
148
|
if args.table.blank?
|
105
|
-
|
149
|
+
abort "Error, no table name specified. Expected usage: rake pg:push_table[prices]"
|
106
150
|
end
|
107
151
|
|
108
152
|
# Find and parse my heroku database info
|
@@ -113,14 +157,14 @@ namespace :pg do
|
|
113
157
|
if info.blank? || info.length != 6
|
114
158
|
puts "Unable to find heroku DATABASE_URL"
|
115
159
|
puts "Expected \"heroku config --remote #{args.remote} | grep DATABASE_URL\" to be present"
|
116
|
-
|
160
|
+
abort
|
117
161
|
end
|
118
162
|
|
119
163
|
heroku = { username: info[1], password: info[2], host: info[3], port: info[4], database: info[5] }
|
120
164
|
|
121
165
|
# Confirm destructive operation
|
122
166
|
puts "WARNING: this task will overwrite the #{args.table} database table on #{args.remote}. Proceed? (y/n)"
|
123
|
-
(
|
167
|
+
abort('Aborted') unless STDIN.gets.chomp.downcase == 'y'
|
124
168
|
|
125
169
|
puts "=== Cloning local table '#{args.table}' to remote #{args.remote} database"
|
126
170
|
|
@@ -129,7 +173,7 @@ namespace :pg do
|
|
129
173
|
tmpfile = "tmp/#{args.table}.sql"
|
130
174
|
|
131
175
|
unless system("pg_dump --data-only --table=#{args.table} -h localhost -U '#{db['username']}' '#{db['database']}' > #{tmpfile}")
|
132
|
-
|
176
|
+
abort "Error dumping local database table"
|
133
177
|
end
|
134
178
|
|
135
179
|
# Now restore it to heroku
|
@@ -137,11 +181,11 @@ namespace :pg do
|
|
137
181
|
delete = args.table.split(',').map { |table| "DELETE FROM #{table}" }.join(';')
|
138
182
|
|
139
183
|
unless system("#{psql} -c \"#{delete}\"")
|
140
|
-
|
184
|
+
abort "Error deleting remote table data"
|
141
185
|
end
|
142
186
|
|
143
187
|
unless system("#{psql} < #{tmpfile}")
|
144
|
-
|
188
|
+
abort "Error pushing table to remote database"
|
145
189
|
end
|
146
190
|
|
147
191
|
# Delete tmpfile
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_developer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
121
|
+
rubygems_version: 3.1.2
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Provides some quality of life developer tools.
|