heroku_migrator 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.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku_migrator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 James Conroy-Finn
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,33 @@
1
+ # HerokuMigrator
2
+
3
+ This gem is provided AS-IS with no warranty or guarantees. If you run
4
+ this gem you will be moving data in your Heroku database. There's a
5
+ chance you will lose data. Back everything up before you even think
6
+ about running heroku_migrator!
7
+
8
+ ## Installation
9
+
10
+ Install it yourself using:
11
+
12
+ $ gem install heroku_migrator
13
+
14
+ ## Usage
15
+
16
+ ```
17
+ Usage:
18
+ heroku_migrator migrate APP
19
+
20
+ Options:
21
+ -m, [--maintenance] # Use maintenance mode while copying data between databases
22
+ # Default: true
23
+ -d, [--database-type=DATABASE_TYPE] # Specify the type of database to provision. http://www.heroku.com/pricing
24
+ # Default: heroku-postgresql:dev
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'heroku_migrator/cli'
4
+ HerokuMigrator::CLI.start
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku_migrator/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'heroku_migrator'
8
+ gem.version = HerokuMigrator::VERSION
9
+ gem.authors = ['James Conroy-Finn']
10
+ gem.email = ['james@logi.cl']
11
+ gem.description = %q{Migrate your deprecated Heroku database quickly}
12
+ gem.summary = %q{Migrate your deprecated Heroku database quickly}
13
+ gem.homepage = 'https://github.com/evently/heroku_migrator'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'heroku', '~> 2.30'
21
+ gem.add_dependency 'thor', '~> 0.15'
22
+
23
+ gem.required_ruby_version = Gem::Requirement.new('~> 1.9')
24
+ gem.post_install_message = <<EOS
25
+ This gem is provided AS-IS with no warranty or guarantees!
26
+
27
+ If you run this gem you will be moving data in your Heroku database. There's a
28
+ chance you will lose data. Back everything up before you even think about
29
+ running heroku_migrator!
30
+ EOS
31
+ end
@@ -0,0 +1,106 @@
1
+ require 'thor'
2
+
3
+ begin
4
+ require 'posix-spawn'
5
+ rescue LoadError
6
+ end
7
+
8
+ module HerokuMigrator
9
+ class CLI < Thor
10
+ include Thor::Actions
11
+
12
+ default_task :help
13
+
14
+ desc 'migrate APP', 'Migrate your database'
15
+
16
+ method_option :maintenance, type: :boolean, aliases: '-m', default: true,
17
+ desc: 'Use maintenance mode while copying data between databases'
18
+
19
+ method_option :database_type, type: :string, aliases: '-d',
20
+ default: 'heroku-postgresql:dev',
21
+ desc: 'Specify the type of database to provision. http://www.heroku.com/pricing'
22
+
23
+ def migrate(app)
24
+ @app = app
25
+
26
+ provision_new_database
27
+
28
+ maintenance do
29
+ copy_database_contents
30
+ promote_new_database
31
+ end
32
+
33
+ deprovision_old_database if yes?('Remove old database?')
34
+
35
+ say DATA.read, :green
36
+ end
37
+
38
+ private
39
+
40
+ def app_option
41
+ "-a #{@app}"
42
+ end
43
+
44
+ def tell_heroku(cmd)
45
+ run "heroku #{cmd} #{app_option}"
46
+ exit $?.exitstatus unless $?.success?
47
+ end
48
+
49
+ def addons
50
+ @addons ||= `heroku addons #{app_option}`.lines.to_a[1..-1]
51
+ end
52
+
53
+ def addon_present?(addon)
54
+ addons.any? { |description| description.include?(addon) }
55
+ end
56
+
57
+ def add_addon(addon)
58
+ tell_heroku "addons:add #{addon}" unless addon_present?(addon)
59
+ end
60
+
61
+ def provision_new_database
62
+ add_addon options[:database_type]
63
+ add_addon 'pgbackups'
64
+ end
65
+
66
+ def copy_database_contents
67
+ tell_heroku "pgbackups:capture --expire --confirm #{@app}"
68
+ tell_heroku "pgbackups:restore #{pg_color} --confirm #{@app}"
69
+ end
70
+
71
+ def promote_new_database
72
+ tell_heroku "pg:promote #{pg_color}"
73
+ end
74
+
75
+ def deprovision_old_database
76
+ tell_heroku 'addons:remove shared-database'
77
+ end
78
+
79
+ def maintenance_mode(state)
80
+ tell_heroku "maintenance:#{state}"
81
+ end
82
+
83
+ def maintenance
84
+ maintenance_mode(:on) if options[:maintenance]
85
+
86
+ yield
87
+
88
+ if options[:maintenance] && yes?('Are you happy to go live?')
89
+ maintenance_mode(:off)
90
+ end
91
+ end
92
+
93
+ def pg_color
94
+ @pg_color ||= `heroku config #{app_option} | grep POSTGRESQL`.split(':').
95
+ first.sub(/_URL$/, '')
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ __END__
102
+
103
+ Congratulations! You've finished migrating your data. Now go claim your reward!
104
+
105
+ https://postgres.heroku.com/migration/
106
+
@@ -0,0 +1,3 @@
1
+ module HerokuMigrator
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1 @@
1
+ require 'heroku_migrator/version'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku_migrator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Conroy-Finn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: heroku
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.30'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.30'
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.15'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.15'
46
+ description: Migrate your deprecated Heroku database quickly
47
+ email:
48
+ - james@logi.cl
49
+ executables:
50
+ - heroku_migrator
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/heroku_migrator
60
+ - heroku_migrator.gemspec
61
+ - lib/heroku_migrator.rb
62
+ - lib/heroku_migrator/cli.rb
63
+ - lib/heroku_migrator/version.rb
64
+ homepage: https://github.com/evently/heroku_migrator
65
+ licenses: []
66
+ post_install_message: ! 'This gem is provided AS-IS with no warranty or guarantees!
67
+
68
+
69
+ If you run this gem you will be moving data in your Heroku database. There''s a
70
+
71
+ chance you will lose data. Back everything up before you even think about
72
+
73
+ running heroku_migrator!
74
+
75
+ '
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: '1.9'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.23
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Migrate your deprecated Heroku database quickly
97
+ test_files: []
98
+ has_rdoc: