Heroku

How It Works

Running Rake Commands on Heroku

Last Updated: 26 January 2012

bamboo

This article applies to apps on the Aspen or Bamboo stacks. For the most recent stack, Cedar, see one-off admin proceseses.

Rake tasks are executed on Heroku’s dyno grid, within the same environment as your app’s dynos. You can run rake tasks within the remote app environment using the heroku rake command as follows:

$ heroku rake db:version
(in /home/slugs/41913_06f36ef_ab3a/mnt)
Current version: 20081118092504

You can pass rake arguments, run multiple tasks, and pass environment variables just as you would locally. For instance, to migrate the database to a specific version with verbose backtraces:

$ heroku rake --trace db:migrate VERSION=20081118092504

After running a migration you’ll want to restart your app with heroku restart to reload the schema and pickup any schema changes.

Limitations

Not all Rake features are supported on Heroku. The following is a list of known limitations:

  • Rake tasks that write to disk, such as rake db:schema:dump, are not compatible with Heroku’s read-only filesystem. In most cases, an equivalent heroku command is available. Taps provides an alternative to db:schema:dump.

  • Multiple heroku rake invocations may run on different machines, so you shouldn’t assume that data written to temporary storage in one rake invocation will be available to subsequent invocations.

  • The rake db:reset task is not supported. Heroku apps do not have permission to drop and create databases. Use the heroku pg:reset command instead.

  • Rake tasks cannot read from stdin. Piping data to heroku rake or prompting for user input is not supported.

See the application constraints topic for additional information and potential workarounds.