-
-
Save obfuscurity/3237829 to your computer and use it in GitHub Desktop.
Migrate from Heroku Shared DB to Postgres `dev` Plan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# This script migrates your Heroku app from a Shared DB to a Postgres `dev` Plan | |
# | |
# Usage: | |
# ruby migrate.rb [app_name] | |
# | |
def usage | |
puts "migrate.rb [app_name]" | |
exit 0 | |
end | |
def app_name | |
ARGV.first or usage | |
end | |
def heroku(cmd) | |
full_cmd = "heroku #{cmd} -a #{app_name}" | |
puts full_cmd | |
system full_cmd | |
end | |
def heroku!(cmd) | |
heroku(cmd) or exit 1 | |
end | |
def db_name | |
return @db_name if @db_name | |
config_output = `heroku config -a #{app_name} | grep POSTGRESQL` | |
@db_name = config_output.match(/(HEROKU_POSTGRESQL_\w+)_URL/)[1] | |
raise "Can't extract db_color from config_output" if @db_name.nil? | |
@db_name | |
end | |
puts "Let's migrate #{app_name} over to Heroku Postgres Dev Plan" | |
heroku "addons:add heroku-postgresql:dev" | |
heroku "addons:add pgbackups" | |
heroku! "maintenance:on" | |
heroku! "pgbackups:capture --expire" | |
heroku! "pgbackups:restore #{db_name} --confirm #{app_name}" | |
heroku! "pg:promote #{db_name}" | |
heroku! "maintenance:off" | |
heroku! "addons:remove shared-database --confirm #{app_name}" | |
puts "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment