Skip to content

Instantly share code, notes, and snippets.

@lenary
Created August 4, 2012 10:00
Show Gist options
  • Save lenary/3256490 to your computer and use it in GitHub Desktop.
Save lenary/3256490 to your computer and use it in GitHub Desktop.
Auto-migrator for heroku databases
# ALL destructive actions still need to be confirmed manually by the user.
# It's also worth pointing out that in special cases, things may not work.
# Most of this info is gleaned from https://devcenter.heroku.com/articles/migrating-from-shared-database-to-heroku-postgres
set -e
APP=$1
echo "APP = $APP"
heroku addons:add heroku-postgresql:dev -a $APP
heroku addons:add pgbackups -a $APP
heroku maintenance:on -a $APP
heroku pgbackups:capture --expire -a $APP
COLOUR_URL=`heroku config -a $APP | grep HEROKU_POSTGRESQL | cut -f 1 -d ":" | head -1`
COLOUR_STRING=`heroku config -a $APP | grep HEROKU_POSTGRESQL | cut -f 1-3 -d "_" | head -1`
echo "COLOUR_URL = $COLOUR_URL; COLOUR_STRING = $COLOUR_STRING"
heroku pgbackups:restore $COLOUR_URL -a $APP
heroku pg:promote $COLOUR_STRING -a $APP
heroku maintenance:off -a $APP
heroku addons:remove shared-database -a $APP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment