heroku_pull 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 885d489c033a394d69e2f626f0603cf4205a54b2
4
+ data.tar.gz: 78e5e59fef91a2dcdc525c901815dfcbefc6676a
5
+ SHA512:
6
+ metadata.gz: efed176155c4acac02b54b03e99d77b299f7537018c83dd7764dc5cfe7038b27354c0ccc0fbaad864b66d3f17e0dc0cd922e65471241570644aba393f8cae577
7
+ data.tar.gz: b654139c33ec7e6e69b4cd4e9752e6231c517b5d7a893fe27605a48964bd3fb7c406771d8e6bc23e3cbf808d3ebed845aad6f272f5aeb3beeae7e542481a3725
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku-pull.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Padilla
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Heroku::Pull
2
+
3
+ Pull the Postgres database from Heroku Rails application into your local server.
4
+
5
+ ## Works great with
6
+
7
+ [Heroku][1] and [Postgres.app][2]
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'heroku_pull', group: :development
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install heroku-pull
22
+
23
+ ## Usage
24
+
25
+ Run
26
+
27
+ $ rake heroku:pull
28
+
29
+ And this should automatically overwrite your local development database
30
+ with a snapshot of the current database of your Heroku app.
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
39
+
40
+
41
+ [1]: http://heroku.com
42
+ [2]: http://postgresapp.com
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/*_test.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku_pull/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heroku_pull"
8
+ spec.version = Heroku::Pull::VERSION
9
+ spec.authors = ["David Padilla"]
10
+ spec.email = ["david@crowdint.com"]
11
+ spec.description = %q{Pull the current Postgres database from Heroku into your local server}
12
+ spec.summary = %q{Pull the current Postgres database from Heroku into your local server}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'railties'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rr"
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/railtie'
2
+
3
+ module HerokuPull
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ namespace :heroku do
7
+ desc "Pull the Postgres database from Heroku into local server"
8
+ task :pull do
9
+ HerokuPull.capture
10
+ HerokuPull.download
11
+ HerokuPull.restore
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Heroku
2
+ module Pull
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require "heroku_pull/version"
2
+ require "heroku_pull/railtie"
3
+ require "yaml"
4
+
5
+ module HerokuPull
6
+ class << self
7
+ def capture
8
+ cmd = "heroku pgbackups:capture --expire"
9
+ puts "Capture the database..."
10
+ puts cmd
11
+ system cmd
12
+ end
13
+
14
+ def download
15
+ cmd = "wget -O #{filename} `heroku pgbackups:url`"
16
+ puts "Download backup file..."
17
+ puts cmd
18
+ system cmd
19
+ end
20
+
21
+ def restore
22
+ cmd = "pg_restore --verbose --clean --no-acl --no-owner -h localhost -d #{database} #{filename}"
23
+ puts "Restore local database..."
24
+ puts cmd
25
+ system cmd
26
+ end
27
+
28
+ def filename
29
+ "./tmp/heroku_pull.sql"
30
+ end
31
+
32
+ def database(config_path = './config/database.yml')
33
+ ENV['RAILS_ENV'] ||= 'development'
34
+ config = YAML::load_file(config_path)
35
+ database = config[ENV['RAILS_ENV']]['database']
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class HerokuPullTest < Test::Unit::TestCase
4
+ def setup
5
+ stub(HerokuPull).puts
6
+ end
7
+
8
+ def test_capture
9
+ expected_cmd = "heroku pgbackups:capture --expire"
10
+ mock(HerokuPull).system expected_cmd
11
+
12
+ HerokuPull.capture
13
+ end
14
+
15
+ def test_download
16
+ expected_cmd = "wget -O ./tmp/heroku_pull.sql `heroku pgbackups:url`"
17
+ mock(HerokuPull).system expected_cmd
18
+
19
+ HerokuPull.download
20
+ end
21
+
22
+ def test_restore
23
+ stub(HerokuPull).database { "test_db" }
24
+ expected_cmd = "pg_restore --verbose --clean --no-acl --no-owner -h localhost -d test_db ./tmp/heroku_pull.sql"
25
+ mock(HerokuPull).system expected_cmd
26
+
27
+ HerokuPull.restore
28
+ end
29
+
30
+ def test_filename
31
+ assert_equal "./tmp/heroku_pull.sql", HerokuPull.filename
32
+ end
33
+
34
+ def test_database
35
+ assert_equal "test_db", HerokuPull.database('test/config/database.yml')
36
+ end
37
+ end
38
+
39
+
@@ -0,0 +1,2 @@
1
+ development:
2
+ database: test_db
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+
3
+ require 'rr'
4
+ require 'heroku_pull'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku_pull
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Padilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Pull the current Postgres database from Heroku into your local server
70
+ email:
71
+ - david@crowdint.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - heroku-pull.gemspec
83
+ - lib/heroku_pull.rb
84
+ - lib/heroku_pull/railtie.rb
85
+ - lib/heroku_pull/version.rb
86
+ - test/cases/heroku_pull_test.rb
87
+ - test/config/database.yml
88
+ - test/test_helper.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.0.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Pull the current Postgres database from Heroku into your local server
113
+ test_files:
114
+ - test/cases/heroku_pull_test.rb
115
+ - test/config/database.yml
116
+ - test/test_helper.rb