Skip to content

Instantly share code, notes, and snippets.

@pcreux
Created August 2, 2012 10:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pcreux/3236123 to your computer and use it in GitHub Desktop.
Save pcreux/3236123 to your computer and use it in GitHub Desktop.
Migrate from Heroku Shared DB to Postgres `dev` Plan
#!/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