lib/tasks/pg_pull.rake in effective_developer-0.8.2 vs lib/tasks/pg_pull.rake in effective_developer-0.8.3
- old
+ new
@@ -12,14 +12,14 @@
# bundle exec rake pg:pull filename=latest.dump database=example
# bundle exec rake pg:pull filename=latest.dump database=example logs=true
# DATABASE=example bundle exec rake pg:load
desc 'Creates a new backup on remote server and downloads it to latest.dump'
task :pull, [:remote] => :environment do |t, args|
- defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }
- env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'].to_s.presence }
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }.compact
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'] }.compact
keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
- args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
+ args.with_defaults(defaults.merge(env_keys).merge(keywords))
# Validate Config
configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
config = configs.first
@@ -40,11 +40,11 @@
unless system("heroku pg:backups:capture --remote #{args.remote}")
abort("Error capturing heroku backup")
end
# Download it to local
- unless system("curl -o #{args.filename} `heroku pg:backups:public-url --remote #{args.remote}`")
+ unless system("curl -o #{args.filename} `heroku pg:backups:url --remote #{args.remote}`")
abort("Error downloading database")
end
# Load it
Rake::Task['pg:load'].invoke(*args)
@@ -91,14 +91,14 @@
# bundle exec rake pg:load[something.dump] => Will replace the current database with something.dump
# bundle exec rake pg:load filename=latest.dump database=example
# DATABASE=example bundle exec rake pg:load
desc 'Loads a postgresql .dump file into the development database (latest.dump by default)'
task :load, [:filename] => :environment do |t, args|
- defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }
- env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }.compact
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }.compact
keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
- args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
+ args.with_defaults(defaults.merge(env_keys).merge(keywords))
# Validate filename
unless File.exist?(Rails.root + args.filename)
puts "#{args.filename || none} does not exist"; exit
end
@@ -141,14 +141,14 @@
# bundle exec rake pg:save => Will dump the database to latest.dump
# bundle exec rake pg:save[something.dump] => Will dump the database to something.dump
desc 'Saves the development database to a postgresql .dump file (latest.dump by default)'
task :save, [:filename] => :environment do |t, args|
- defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }
- env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'].to_s.presence }
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }.compact
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'] }.compact
keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
- args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
+ args.with_defaults(defaults.merge(env_keys).merge(keywords))
db = if ENV['DATABASE_URL'].to_s.length > 0 && args.database.blank?
uri = URI.parse(ENV['DATABASE_URL']) rescue nil
abort("Invalid DATABASE_URL") unless uri.present?
@@ -208,13 +208,13 @@
Bundler.with_unbundled_env do
unless system("heroku pg:backups:capture --app #{args.source}")
abort "Error capturing heroku backup"
end
- url = (`heroku pg:backups:public-url --app #{args.source}`).chomp
+ url = (`heroku pg:backups:url --app #{args.source}`).chomp
unless (url || '').length > 0
- abort "Error reading public-url from app #{args.source}"
+ abort "Error reading url from app #{args.source}"
end
unless system("heroku pg:backups:restore '#{url}' DATABASE_URL --app #{args.target}")
abort "Error cloning heroku backup"
end