Skip to content

Instantly share code, notes, and snippets.

@josephwegner
Created June 24, 2013 20:25
Show Gist options
  • Select an option

  • Save josephwegner/5853304 to your computer and use it in GitHub Desktop.

Select an option

Save josephwegner/5853304 to your computer and use it in GitHub Desktop.
Deploy lessonnote to heroku with migrations
[check if `heroku` is installed]
# Note, that for production, you're going to need to find+replace lessonnote-staging to lessonnote-production
heroku maintenance:on --app lessonnote-staging
# Nato: The output of
# git tags
# will look like this:
#
# 1.0
# 1.1
# 1.2
# 2.0
# 2.2
oldver = [NATO!]
newver = [NATO!]
#Now we need to push the git repository to heroku.
#but it's probably safer to check if the remote exists, first.
# Nato: The output of
# git remote
# will look like this:
#
# lessonnote-production
# lessonnote-staging
# master
#
# You just need to check if lessonnote-staging exists in that list
# If it doesn't fail the script and give some useful error message
#After that we do the actual push. You will want the porcelain output, so it should look like this:
git push -f --porcelain lessonnote-staging $newver^{}:master
#Note that the real syntax, without variables, is git push -f --porcelain lessonnote-staging v2.2^{}:master
# Check the output of the above command. The last line should be "Done". No quotes.
# Otherwise it might be nice to output the last 10 lines or something
#Now we want to run the migrations
heroku run rake db:migrate --app lessonnote-staging
#You're going to want to run the output of that and check for
#
# rake aborted!
#
# If you see that, follow the error path.
# IF NO RAKE ERROR
#All is well, let's turn maintenance mode off
heroku maintenance:off --app lessonnote-staging
# Output something nice. Like some ASCII art of a rainbow pooping flowers.
# Or just a message letting us know it worked.
# ELSE IF RAKE ERROR
# Now we need to roll back the code, and turn off maintenance mode
git push -f --porcelain lessonnote-staging $oldver^{}:master
#Check that again that it ended with
# Done
#If it didn't give a hard error and explain that the deployment failed, but you were unable to rollback.
#The server is still in maintenance mode, and will need to be manually rectified
#Otherwise...
heroku maintenance:off --app lessonnote-staging
#Now output something about the deployment failing and being rolled back to the previous version.
#If you're super nice, you would output some of the error from that db:migrate command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment