Skip to content
A Rails template with our standard defaults, ready to deploy to Heroku.
Ruby HTML Shell CSS
Branch: master
Clone or download
2 authors and composerinteralia Use Release Phase for database migration
Heroku's [Release
Phase](https://devcenter.heroku.com/articles/release-phase) feature
provides a much better migration experience for a production deploy of a
Rails application.

Without using a release phase task, here's how you migrate your database
in production:

1. Deploy your application via Git or pipeline promotion.
2. With the migration deployed, run `rake db:migrate`.
3. Immediately restart the application so that Rails is now aware of the
schema changes.

This process is awkward and can lengthen downtime in deploys. It results
in the application being restarted twice (once for the deployment of
code, and then again post-migration), and also may push application
logic that depends on the new code into production before the migration
has run or finished, which can lead to unnecessary exceptions.

There are strategies to mitigate these problems, but they generally
involve many small commits and deploys that must be carefully
orchestrated (not pushed all at once) that can be laborious and error
prone.

This commit leverages the Heroku Release Phase task to execute a
smoother migration. Here's how the process works:

1. Start your deploy with Git or a pipeline promotion
2. Heroku builds or promotes your application slug
3. Before deploying the application code to dynos, a run dyno is started
and it executes the release phase task. In this case, it's a shell
script that runs `rake db:migrate` if the application has an
`AUTO_MIGRATE_DB` environment variable set.
4. After the migration finishes, Heroku deploys the application and
restarts. If the release phase failed (migration problem), the deploy does not
proceed.

This process reduces the chance of new application code that depends on
the un-run migration being deployed and reduces the number of
application restarts from two to one. We've been using it at CommonLit
for several months now and noticed a dramatic downturn in
deployment-related downtime.

Co-authored-by: Dan Moore <dan@vaporwa.re>
Latest commit 5b68a17 Aug 26, 2019

README.md

Suspenders Build Status Reviewed by Hound

Suspenders is the base Rails application used at thoughtbot.

Suspenders boy

Installation

First install the suspenders gem:

gem install suspenders

Then run:

suspenders projectname

This will create a Rails app in projectname using the latest version of Rails.

Associated services

Gemfile

To see the latest and greatest gems, look at Suspenders' Gemfile, which will be appended to the default generated projectname/Gemfile.

It includes application gems like:

And development gems like:

  • Dotenv for loading environment variables
  • Pry Rails for interactively exploring objects
  • ByeBug for interactively debugging behavior
  • Bullet for help to kill N+1 queries and unused eager loading
  • Bundler Audit for scanning the Gemfile for insecure dependencies based on published CVEs
  • Spring for fast Rails actions via pre-loading
  • Web Console for better debugging via in-browser IRB consoles.

And testing gems like:

Other goodies

Suspenders also comes with:

Heroku

Read the documentation on deploying to Heroku

You can optionally create Heroku staging and production apps:

suspenders app --heroku true

This:

  • Creates a staging and production Heroku app
  • Sets them as staging and production Git remotes
  • Configures staging with HONEYBADGER_ENV environment variable set to staging
  • Creates a Heroku Pipeline for review apps
  • Schedules automated backups for 10AM UTC for both staging and production

You can optionally specify alternate Heroku flags:

suspenders app \
  --heroku true \
  --heroku-flags "--region eu --addons sendgrid,ssl"

See all possible Heroku flags:

heroku help create

Git

This will initialize a new git repository for your Rails app. You can bypass this with the --skip-git option:

suspenders app --skip-git true

GitHub

You can optionally create a GitHub repository for the suspended Rails app. It requires that you have Hub on your system:

curl https://hub.github.com/standalone -sLo ~/bin/hub && chmod +x ~/bin/hub
suspenders app --github organization/project

This has the same effect as running:

hub create organization/project

Spring

Suspenders uses spring by default. It makes Rails applications load faster, but it might introduce confusing issues around stale code not being refreshed. If you think your application is running old code, run spring stop. And if you'd rather not use spring, add DISABLE_SPRING=1 to your login file.

Dependencies

Suspenders requires the latest version of Ruby.

Some gems included in Suspenders have native extensions. You should have GCC installed on your machine before generating an app with Suspenders.

Use OS X GCC Installer for Snow Leopard (OS X 10.6).

Use Command Line Tools for Xcode for Lion (OS X 10.7) or Mountain Lion (OS X 10.8).

We use Google Chromedriver for full-stack JavaScript integration testing. It requires Google Chrome or Chromium.

PostgreSQL needs to be installed and running for the db:create rake task.

Issues

If you have problems, please create a GitHub Issue.

Contributing

See CONTRIBUTING.md.

Thank you, contributors!

License

Suspenders is Copyright © 2008-2017 thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About thoughtbot

thoughtbot

Suspenders is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects. We are available for hire.

You can’t perform that action at this time.