effective_developer 0.6.0 → 0.6.1

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: 0db076604fcb663e2f5ad49b01da50837dfde6c9ae38b9be6d6ba3b265504a44
4
- data.tar.gz: cd78feba26b117b151bdea4b0f6840d5bb01851b9d522d2e0df4bb68dd669f4e
3
+ metadata.gz: fc26ec312df01c35b4f0541fbb8fee46f5b93c32c615cd3c1f0c8c659b67110a
4
+ data.tar.gz: 74a960c89033ea9531c3d0950e97d2e4bcac7c4d7a64ee4e9bc6cd1029e7ac51
5
5
  SHA512:
6
- metadata.gz: '0338a8bcac5b91c619acf7b4137c26a992a5398ee79444e50f47efee88051ba2bbf128998c095086de636fec797f246e778e9a2139a4644651b399e1c170863d'
7
- data.tar.gz: 90f4c12d302a98c1be2e46da4b0d04bbc123953ddebd4864a8dd79d2837273ebf58a7492bd244fd9e78df3642286729d762dfb82f7a751e080c772001dd025ea
6
+ metadata.gz: d63cb384af0910ac4f33e2696e4c72ab388fce049c31e35174bd940da6cbfc699e0bc5dcf821e72a60a1d000d6644b351ed231d9b5c5a180bcca8da7d71f5566
7
+ data.tar.gz: efeb52d66a9c083038609146ac5901ed8cd9521ff5ef74e0cd7537d4ac1fe2d9609095a2d79d998150612c7e2e52ce11ab1f377b824cd6bac21a574d62c1701b
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
@@ -4,14 +4,35 @@ namespace :pg do
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
+
8
+ # bundle exec rake pg:pull
9
+ # bundle exec rake pg:pull[staging]
10
+ # bundle exec rake pg:pull[158.204.33.124]
11
+ # bundle exec rake pg:pull filename=latest.dump database=example
12
+ # DATABASE=example bundle exec rake pg:load
7
13
  desc 'Creates a new backup on remote server and downloads it to latest.dump'
8
14
  task :pull, [:remote] => :environment do |t, args|
15
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }
16
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }
17
+ keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
18
+ args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
19
+
20
+ # Validate Config
21
+ config = ActiveRecord::Base.configurations[Rails.env]
22
+ configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
23
+
24
+ if configs.length > 1 && args.database.blank?
25
+ puts "Multiple database configs exist for #{Rails.env} environment."
26
+ puts "Please run bundle exec rake pg:pull database=x"
27
+ puts "Where x is one of: #{configs.map { |config| config.name }.to_sentence}"
28
+ exit
29
+ end
9
30
 
10
31
  # Heroku mode
11
32
  if `git remote -v | grep heroku`.length > 0
12
33
  args.with_defaults(remote: 'heroku')
13
34
 
14
- puts "=== Pulling remote '#{args.remote}' database into latest.dump"
35
+ puts "=== Pulling remote '#{args.remote}' #{args.database} database into #{args.filename}"
15
36
 
16
37
  # Create a backup on heroku
17
38
  unless system("heroku pg:backups:capture --remote #{args.remote}")
@@ -19,12 +40,12 @@ namespace :pg do
19
40
  end
20
41
 
21
42
  # Download it to local
22
- unless system("curl -o latest.dump `heroku pg:backups:public-url --remote #{args.remote}`")
43
+ unless system("curl -o #{args.filename} `heroku pg:backups:public-url --remote #{args.remote}`")
23
44
  abort("Error downloading database")
24
45
  end
25
46
 
26
47
  # Load it
27
- Rake::Task['pg:load'].invoke
48
+ Rake::Task['pg:load'].invoke(*args)
28
49
  exit
29
50
  end
30
51
 
@@ -36,24 +57,24 @@ namespace :pg do
36
57
  user: ENV['HATCHBOX_USER'] || 'deploy'
37
58
  )
38
59
 
39
- puts "=== Pulling hatchbox '#{args.remote}' #{args.app} database into latest.dump"
60
+ puts "=== Pulling hatchbox '#{args.remote}' #{args.app} #{args.database} database into #{args.filename}"
40
61
 
41
62
  # SSH into hatchbox and call rake pg:save there to create latest.dump
42
- unless(result = `ssh #{args.user}@#{args.remote} << EOF
63
+ unless(result = `ssh -T #{args.user}@#{args.remote} << EOF
43
64
  cd ~/#{args.app}/current/
44
- bundle exec rake pg:save[latest.dump]
65
+ bundle exec rake pg:save database=#{args.database} filename=#{args.filename}
45
66
  `).include?('Saving database completed') # The output of pg:save down below
46
67
  puts("Error calling ssh #{args.user}@#{args.remote} and running rake pg:save on hatchbox from ~/#{args.app}/current/")
47
68
  abort(result)
48
69
  end
49
70
 
50
71
  # SCP to copy the hatchkbox latest.dump to local
51
- unless system("scp #{args.user}@#{args.remote}:~/#{args.app}/current/latest.dump ./")
72
+ unless system("scp #{args.user}@#{args.remote}:~/#{args.app}/current/#{args.filename} ./")
52
73
  abort("Error downloading database")
53
74
  end
54
75
 
55
76
  # Load it
56
- Rake::Task['pg:load'].invoke
77
+ Rake::Task['pg:load'].invoke(*args)
57
78
  exit
58
79
  end
59
80
 
@@ -67,6 +88,7 @@ namespace :pg do
67
88
  # bundle exec rake pg:load => Will replace the current database with latest.dump
68
89
  # bundle exec rake pg:load[something.dump] => Will replace the current database with something.dump
69
90
  # bundle exec rake pg:load filename=latest.dump database=example
91
+ # DATABASE=example bundle exec rake pg:load
70
92
  desc 'Loads a postgresql .dump file into the development database (latest.dump by default)'
71
93
  task :load, [:filename] => :environment do |t, args|
72
94
  defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }
@@ -106,19 +128,6 @@ namespace :pg do
106
128
 
107
129
  puts "=== Loading #{args.filename} into local '#{db[:database]}' database"
108
130
 
109
- # bin/rails db:environment:set RAILS_ENV=development
110
- if Rails.env != 'production'
111
- ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1'
112
- end
113
-
114
- if configs.length > 1
115
- Rake::Task["db:drop:#{args.database}"].invoke
116
- Rake::Task["db:create:#{args.database}"].invoke
117
- else
118
- Rake::Task['db:drop'].invoke
119
- Rake::Task['db:create'].invoke
120
- end
121
-
122
131
  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.filename}")
123
132
  puts "Loading database completed"
124
133
  else
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.6.0
4
+ version: 0.6.1
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: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails