effective_developer 0.4.15 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f7cccd4c476002105c649c582f9fe243d7ec605941756b705c0fba8012cd8db
4
- data.tar.gz: dddc8875b4723c497471b4445e42c6e45de0c59fab4a2493062d608b236fa68d
3
+ metadata.gz: 9b699364e669ff684e3f426ba3a61ff3d3ed9033fc5de0d87e47f0525aab757f
4
+ data.tar.gz: 4c86bfca263befc898633b2d260b9a439da0da12257afeb66cf45413786c714d
5
5
  SHA512:
6
- metadata.gz: 8301e15ea438d1e927b601824f96a352ce996d653200e21509bdceb738f2f69bdbb522d7570656e3d6265a6607d0574f312ebb44624ae31f2063aa840f56af11
7
- data.tar.gz: 8f89d98d3413016395f27d4d1576c1c6514a0820734f18f4acde0374d6c66eb954554349ead83aaddbfb26711d8afce83213cf94ebbb58bc109304a7292a8da9
6
+ metadata.gz: 193641e2323b3fb9d68f77e4d429021d2064a142feeb040e6f08ff3fa24ae0452ee6016e42f363746144a9c5ce26f51b9d92af6901a7c1e8987ec508df91bbfb
7
+ data.tar.gz: 97783809f4dc074280d343b59803e8d1a3d23c5ea49e19cdaebdacfc9575abfe66f32b077435f966887f1270c631bf96f94ee6e9baa06ce3d93584223c8013f8
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.4.15'.freeze
2
+ VERSION = '0.5.3'.freeze
3
3
  end
@@ -6,17 +6,60 @@ namespace :pg do
6
6
  # bundle exec rake pg:pull[158.204.33.124]
7
7
  desc 'Creates a new backup on remote server and downloads it to latest.dump'
8
8
  task :pull, [:remote] => :environment do |t, args|
9
+
10
+ # Heroku mode
9
11
  if `git remote -v | grep heroku`.length > 0
10
- Rake::Task['heroku:pg:pull'].invoke(args[:remote])
11
- elsif (args[:remote] || ENV['HATCHBOX_IP']).to_s.count('.') == 3
12
- Rake::Task['hatchbox:pg:pull'].invoke(args[:remote])
13
- else
14
- puts "Unable to find pg:pull provider."
15
- puts "Please add a heroku git remote or a HATCHBOX_IP environment variable and try again"
12
+ args.with_defaults(remote: 'heroku')
13
+
14
+ puts "=== Pulling remote '#{args.remote}' database into latest.dump"
15
+
16
+ # Create a backup on heroku
17
+ unless system("heroku pg:backups:capture --remote #{args.remote}")
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
16
28
  exit
17
29
  end
18
30
 
19
- Rake::Task['pg:load'].invoke
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)
48
+ end
49
+
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")
53
+ end
54
+
55
+ # Load it
56
+ Rake::Task['pg:load'].invoke
57
+ exit
58
+ end
59
+
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
20
63
  end
21
64
 
22
65
  # Drops and re-creates the local database then initializes database with latest.dump
@@ -29,6 +72,7 @@ namespace :pg do
29
72
 
30
73
  config = ActiveRecord::Base.configurations[Rails.env]
31
74
  db = { username: (config['username'] || `whoami`), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
75
+ db.transform_values! { |v| v.respond_to?(:chomp) ? v.chomp : v }
32
76
 
33
77
  puts "=== Loading #{args.file_name} into local '#{db[:database]}' database"
34
78
 
@@ -43,7 +87,7 @@ namespace :pg do
43
87
  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}")
44
88
  puts "Loading database completed"
45
89
  else
46
- puts "Error loading database"
90
+ abort "Error loading database"
47
91
  end
48
92
  end
49
93
 
@@ -54,25 +98,23 @@ namespace :pg do
54
98
  args.with_defaults(:file_name => 'latest.dump')
55
99
 
56
100
  db = if ENV['DATABASE_URL'].to_s.length > 0
57
- regex = Regexp.new(/postgres:\/\/(\w+):(\w+)@(.+):(\d+)\/(\w+)/)
58
- info = ENV['DATABASE_URL'].match(regex)
101
+ uri = URI.parse(ENV['DATABASE_URL']) rescue nil
102
+ abort("Invalid DATABASE_URL") unless uri.present?
59
103
 
60
- if info.blank? || info.length != 6
61
- puts("Invalid DATABASE_URL") and exit
62
- end
63
-
64
- { username: info[1], password: info[2], host: info[3], port: info[4], database: info[5] }
104
+ { username: uri.user, password: uri.password, host: uri.host, port: (uri.port || 5432), database: uri.path.sub('/', '') }
65
105
  else
66
106
  config = ActiveRecord::Base.configurations[Rails.env]
67
- { username: (config['username'] || `whoami`), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
107
+ { username: (config['username'] || `whoami`.chomp), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
68
108
  end
69
109
 
110
+ db.transform_values! { |v| v.respond_to?(:chomp) ? v.chomp : v }
111
+
70
112
  puts "=== Saving local '#{db[:database]}' database to #{args.file_name}"
71
113
 
72
114
  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}")
73
115
  puts "Saving database completed"
74
116
  else
75
- puts "Error saving database"
117
+ abort "Error saving database"
76
118
  end
77
119
  end
78
120
 
@@ -85,20 +127,17 @@ namespace :pg do
85
127
 
86
128
  Bundler.with_clean_env do
87
129
  unless system("heroku pg:backups:capture --remote #{args.source_remote}")
88
- puts "Error capturing heroku backup"
89
- exit
130
+ abort "Error capturing heroku backup"
90
131
  end
91
132
 
92
133
  url = (`heroku pg:backups:public-url --remote #{args.source_remote}`).chomp
93
134
 
94
135
  unless (url || '').length > 0
95
- puts "Error reading public-url from remote #{args.source_remote}"
96
- exit
136
+ abort "Error reading public-url from remote #{args.source_remote}"
97
137
  end
98
138
 
99
139
  unless system("heroku pg:backups:restore '#{url}' DATABASE_URL --remote #{args.target_remote}")
100
- puts "Error cloning heroku backup"
101
- exit
140
+ abort "Error cloning heroku backup"
102
141
  end
103
142
  end
104
143
 
@@ -110,7 +149,7 @@ namespace :pg do
110
149
  args.with_defaults(:remote => 'heroku')
111
150
 
112
151
  if args.table.blank?
113
- puts "Error, no table name specified. Expected usage: rake pg:push_table[prices]"; exit
152
+ abort "Error, no table name specified. Expected usage: rake pg:push_table[prices]"
114
153
  end
115
154
 
116
155
  # Find and parse my heroku database info
@@ -121,14 +160,14 @@ namespace :pg do
121
160
  if info.blank? || info.length != 6
122
161
  puts "Unable to find heroku DATABASE_URL"
123
162
  puts "Expected \"heroku config --remote #{args.remote} | grep DATABASE_URL\" to be present"
124
- exit
163
+ abort
125
164
  end
126
165
 
127
166
  heroku = { username: info[1], password: info[2], host: info[3], port: info[4], database: info[5] }
128
167
 
129
168
  # Confirm destructive operation
130
169
  puts "WARNING: this task will overwrite the #{args.table} database table on #{args.remote}. Proceed? (y/n)"
131
- (puts 'Aborted' and exit) unless STDIN.gets.chomp.downcase == 'y'
170
+ abort('Aborted') unless STDIN.gets.chomp.downcase == 'y'
132
171
 
133
172
  puts "=== Cloning local table '#{args.table}' to remote #{args.remote} database"
134
173
 
@@ -137,7 +176,7 @@ namespace :pg do
137
176
  tmpfile = "tmp/#{args.table}.sql"
138
177
 
139
178
  unless system("pg_dump --data-only --table=#{args.table} -h localhost -U '#{db['username']}' '#{db['database']}' > #{tmpfile}")
140
- puts "Error dumping local database table"; exit
179
+ abort "Error dumping local database table"
141
180
  end
142
181
 
143
182
  # Now restore it to heroku
@@ -145,11 +184,11 @@ namespace :pg do
145
184
  delete = args.table.split(',').map { |table| "DELETE FROM #{table}" }.join(';')
146
185
 
147
186
  unless system("#{psql} -c \"#{delete}\"")
148
- puts "Error deleting remote table data"; exit
187
+ abort "Error deleting remote table data"
149
188
  end
150
189
 
151
190
  unless system("#{psql} < #{tmpfile}")
152
- puts "Error pushing table to remote database"; exit
191
+ abort "Error pushing table to remote database"
153
192
  end
154
193
 
155
194
  # 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.15
4
+ version: 0.5.3
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-20 00:00:00.000000000 Z
11
+ date: 2020-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -95,8 +95,6 @@ files:
95
95
  - lib/scaffolds/models/model.rb
96
96
  - lib/scaffolds/views/_resource.html.haml
97
97
  - lib/tasks/effective_csv_importer.rake
98
- - lib/tasks/hatchbox.rake
99
- - lib/tasks/heroku.rake
100
98
  - lib/tasks/pg_pull.rake
101
99
  - lib/tasks/rename_class.rake
102
100
  - lib/tasks/reset_pk_sequence.rake
@@ -120,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
118
  - !ruby/object:Gem::Version
121
119
  version: '0'
122
120
  requirements: []
123
- rubygems_version: 3.0.3
121
+ rubygems_version: 3.1.2
124
122
  signing_key:
125
123
  specification_version: 4
126
124
  summary: Provides some quality of life developer tools.
@@ -1,15 +0,0 @@
1
- namespace :hatchbox do
2
- namespace :pg do
3
- # Creates a new backup on heroku, downloads that backup to latest.dump, and then calls pg:load
4
- #
5
- # bundle exec rake heroku:pull
6
- # bundle exec rake heroku:pull[staging]
7
- desc 'Pulls a newly captured backup from heroku (--remote heroku by default) and calls pg:load'
8
- task :pull, [:remote] => :environment do |t, args|
9
- args.with_defaults(remote: ENV['HATCHBOX_IP'])
10
-
11
- puts "=== Pulling remote '#{args.remote}' database into latest.dump"
12
- end
13
-
14
- end
15
- end
@@ -1,28 +0,0 @@
1
- namespace :heroku do
2
- namespace :pg do
3
- # Creates a new backup on heroku, downloads that backup to latest.dump, and then calls pg:load
4
- #
5
- # bundle exec rake heroku:pg:pull
6
- # bundle exec rake heroku:pg:pull[staging]
7
- desc 'Pulls a newly captured backup from heroku (--remote heroku by default)'
8
- task :pull, [:remote] => :environment do |t, args|
9
- args.with_defaults(remote: 'heroku')
10
-
11
- puts "=== Pulling remote '#{args.remote}' database into latest.dump"
12
-
13
- Bundler.with_clean_env do
14
- unless system("heroku pg:backups:capture --remote #{args.remote}")
15
- puts("Error capturing heroku backup")
16
- exit
17
- end
18
-
19
- if system("curl -o latest.dump `heroku pg:backups:public-url --remote #{args.remote}`")
20
- puts "Downloading database completed"
21
- else
22
- puts "Error downloading database"
23
- end
24
- end
25
- end
26
-
27
- end
28
- end