heroku_db_restore 0.0.4
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 +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +3 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/heroku_db_restore.gemspec +35 -0
- data/lib/heroku_db_restore/railtie.rb +5 -0
- data/lib/heroku_db_restore/version.rb +3 -0
- data/lib/heroku_db_restore.rb +6 -0
- data/lib/tasks/db_restore.rake +63 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: da12edd2fd6f1ba04d122df163e303f1f9563124
|
4
|
+
data.tar.gz: 0530b83f059787ed227734e4871cf374e7ec2999
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d551a3401b4a9b47cf9e7ea42585c2d19c9499e59189c6ef3ac6f8c8d8bcba1fad78c60b38c044ddf48d68ca543d220629d524c009a9bd81a992a28244cca779
|
7
|
+
data.tar.gz: 7252c8913f3315c4420dd9613c1fa34abe69878c5d450a3ebe40e4db9e6b5ac2b0e7241da39cac49bcfc9e357dbe36f59c6404940a24288aee9c334f7fd96c19
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 nrowegt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# HerokuDbRestore
|
2
|
+
|
3
|
+
A (for now) very opinionated gem which has 3 sections:
|
4
|
+
|
5
|
+
* pipeline/app setup
|
6
|
+
* db restore (pull down your heroku database and `psql < tmp/latest.db`)
|
7
|
+
* db_restores (push to heroku remotes)
|
8
|
+
|
9
|
+
These tasks all assume your heroku application names are of the format `"#{Rails.application.class.parent_name.underscore.gsub('_','-')}-#{environment}"`, where environment is one of staging, production. Setting up an app includes the following free Heroku addons:
|
10
|
+
|
11
|
+
*heroku-postgresql:hobby-dev
|
12
|
+
*newrelic:wayne
|
13
|
+
*papertrail:choklad
|
14
|
+
*rediscloud:30
|
15
|
+
*scheduler:standard
|
16
|
+
*sendgrid:starter
|
17
|
+
|
18
|
+
App name configuration flags and more detailed documentation will come in a later version.
|
19
|
+
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'heroku_db_restore', group: :development # No need to include this on production or staging
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install heroku_db_restore
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
To see an updated list of tasks and descriptions:
|
39
|
+
`bundle exec rake heroku_db_restore -T heroku_db_restore`
|
40
|
+
|
41
|
+
~~~bash
|
42
|
+
rake db:restore # Pull Down a copy of the database from the specified heroku environment
|
43
|
+
rake db:restore:from_local_dump # Restore from local dump file (defaults to '/tmp/latest.dump' - specify with DUMP_FILE Environmental Variable)
|
44
|
+
rake db:restore:local # Erase local development and test database and restore from the local dump file
|
45
|
+
rake db:restore:production # Restore a local copy of Heroku's Production Environment database
|
46
|
+
rake db:restore:staging # Restore a local copy of Heroku's Staging Environment database
|
47
|
+
~~~
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ldstudios/heroku_db_restore.
|
53
|
+
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "heroku_db_restore"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heroku_db_restore/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "heroku_db_restore"
|
8
|
+
spec.version = HerokuDbRestore::VERSION
|
9
|
+
spec.authors = ["nrowegt", "danielricecodes"]
|
10
|
+
spec.email = ["nrowegt@gmail.com", "daniel.rice@ldstudios.co"]
|
11
|
+
|
12
|
+
spec.summary = "Helpful Heroku Deploy Rake Tasks"
|
13
|
+
spec.description = "Tasks to run appllication db_restores and db restores for heroku:pg databases"
|
14
|
+
spec.homepage = "https://github.com/ldstudios/heroku_db_restore"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc 'Pull Down a copy of the database from the specified heroku environment'
|
3
|
+
task :restore do
|
4
|
+
env = ENV['ENV']
|
5
|
+
|
6
|
+
abort "Please specify ENV=production or ENV=staging" unless env
|
7
|
+
app = app_name_from_environment(env)
|
8
|
+
|
9
|
+
if ENV['LATEST'] #if this is here, then create a fresh backup, if not grab whichever is the latest
|
10
|
+
sh "heroku pg:backups capture --app #{app}"
|
11
|
+
end
|
12
|
+
|
13
|
+
sh "curl -o tmp/latest.dump `heroku pg:backups public-url --app #{app} | head -n 1`"
|
14
|
+
|
15
|
+
#ensures there are no extra tables or views
|
16
|
+
Rake::Task["db:restore:local"].invoke
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :restore do
|
20
|
+
desc "Restore a local copy of Heroku's Staging Environment database"
|
21
|
+
task :staging do
|
22
|
+
ENV['ENV'] = "staging"
|
23
|
+
Rake::Task["db:restore"].invoke
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Restore a local copy of Heroku's Production Environment database"
|
27
|
+
task :production do
|
28
|
+
ENV['ENV'] = "production"
|
29
|
+
Rake::Task["db:restore"].invoke
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Erase local development and test database and restore from the local dump file."
|
33
|
+
task :local do
|
34
|
+
#ensures there are no extra tables or views
|
35
|
+
Rake::Task["db:drop"].invoke
|
36
|
+
Rake::Task["db:create"].invoke
|
37
|
+
|
38
|
+
Rake::Task["db:restore:from_local_dump"].invoke
|
39
|
+
#migrate the database, remove sensitive information, and setup tests
|
40
|
+
Rake::Task["db:migrate"].invoke
|
41
|
+
Rake::Task["db:test:prepare"].invoke
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Restore from local dump file (defaults to '/tmp/latest.dump' - specify with DUMP_FILE Environmental Variable)"
|
45
|
+
task :from_local_dump do
|
46
|
+
dump_file_location = (ENV['DUMP_FILE'] || "tmp/latest.dump")
|
47
|
+
#in backticks so that pg_restore warnings dont exit this routine
|
48
|
+
`pg_restore --verbose --clean --no-acl --no-owner -h localhost -d #{local_database_name} #{dump_file_location}`
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def local_database_name
|
54
|
+
Rails.configuration.database_configuration[Rails.env]["database"]
|
55
|
+
end
|
56
|
+
def app_name_from_environment(env)
|
57
|
+
case env.downcase
|
58
|
+
when "production"
|
59
|
+
ENV['HEROKU_APPNAME_PRODUCTION'] || "#{Rails.application.class.parent_name.underscore.gsub('_','-')}-production"
|
60
|
+
when "staging"
|
61
|
+
ENV['HEROKU_APPNAME_STAGING'] || "#{Rails.application.class.parent_name.underscore.gsub('_','-')}-staging"
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_db_restore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nrowegt
|
8
|
+
- danielricecodes
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.13'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.13'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
description: Tasks to run appllication db_restores and db restores for heroku:pg databases
|
43
|
+
email:
|
44
|
+
- nrowegt@gmail.com
|
45
|
+
- daniel.rice@ldstudios.co
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- heroku_db_restore.gemspec
|
58
|
+
- lib/heroku_db_restore.rb
|
59
|
+
- lib/heroku_db_restore/railtie.rb
|
60
|
+
- lib/heroku_db_restore/version.rb
|
61
|
+
- lib/tasks/db_restore.rake
|
62
|
+
homepage: https://github.com/ldstudios/heroku_db_restore
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata:
|
66
|
+
allowed_push_host: https://rubygems.org
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Helpful Heroku Deploy Rake Tasks
|
87
|
+
test_files: []
|