Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

This demonstrates the problem with trying to run rake db:migrate as part of the slug compilation process when the an app is first deployed to Heroku.

# Create new Rails app
$ rails new --database=postgresql testing-migrations
$ git init
$ git add .
$ git commit -m 'Add empty Rails project'

# Use scaffolding to create a database migration
$ rails g scaffold person name:string
$ git add .
$ git commit -m 'Add person scaffolding'

# Create Heroku app
$ heroku apps:create
Creating app... done, ⬢ calm-ridge-11009 |

# Set Heroku app to use Ruby buildpack
$ heroku buildpacks:set heroku/ruby
Buildpack set. Next release on calm-ridge-11009 will use heroku/ruby.
Run git push heroku master to create a new release using this buildpack.

# Add Rake buildpack to Heroku app
$ heroku buildpacks:add
Buildpack added. Next release on calm-ridge-11009 will use:
  1. heroku/ruby
Run git push heroku master to create a new release using these buildpacks.

# Configure Rake buildpack to run `rake db:migrate`
$ heroku config:set DEPLOY_TASKS=db:migrate
Setting DEPLOY_TASKS and restarting ⬢ calm-ridge-11009... done, v3
DEPLOY_TASKS: db:migrate

# Deploy the app
# Observe that it fails because the database doesn't appear to be available
$ git push heroku master
Counting objects: 101, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (87/87), done.
Writing objects: 100% (101/101), 22.63 KiB | 0 bytes/s, done.
Total 101 (delta 8), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.4
remote: -----> Installing dependencies using bundler 1.11.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from
remote:        Fetching version metadata from
remote:        Fetching dependency metadata from
remote:        Installing i18n 0.7.0
remote:        Installing json 1.8.3 with native extensions
remote:        Installing rake 11.3.0
remote:        Installing minitest 5.9.0
remote:        Installing thread_safe 0.3.5
remote:        Installing builder 3.2.2
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing pkg-config 1.1.7
remote:        Installing rack 1.6.4
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 6.0.3
remote:        Installing coffee-script-source 1.10.0
remote:        Installing execjs 2.7.0
remote:        Installing thor 0.19.1
remote:        Installing concurrent-ruby 1.0.2
remote:        Using bundler 1.11.2
remote:        Installing multi_json 1.12.1
remote:        Installing pg 0.18.4 with native extensions
remote:        Installing sass 3.4.22
remote:        Installing tilt 2.0.5
remote:        Installing turbolinks-source 5.0.0
remote:        Installing tzinfo 1.2.2
remote:        Installing rdoc 4.2.2
remote:        Installing nokogiri 1.6.8 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing mime-types 3.1
remote:        Installing coffee-script 2.4.1
remote:        Installing uglifier 3.0.2
remote:        Installing sprockets 3.7.0
remote:        Installing turbolinks 5.0.1
remote:        Installing activesupport
remote:        Installing sdoc 0.4.1
remote:        Installing mail 2.6.4
remote:        Installing rails-deprecated_sanitizer 1.0.3
remote:        Installing globalid 0.3.7
remote:        Installing activemodel
remote:        Installing jbuilder 2.6.0
remote:        Installing activejob
remote:        Installing activerecord
remote:        Installing rails-dom-testing 1.0.7
remote:        Installing loofah 2.0.3
remote:        Installing rails-html-sanitizer 1.0.3
remote:        Installing actionview
remote:        Installing actionpack
remote:        Installing railties
remote:        Installing actionmailer
remote:        Installing sprockets-rails 3.2.0
remote:        Installing coffee-rails 4.1.1
remote:        Installing jquery-rails 4.2.1
remote:        Installing rails
remote:        Installing sass-rails 5.0.6
remote:        Bundle complete! 12 Gemfile dependencies, 52 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Post-install message from rdoc:
remote:        Depending on your version of ruby, you may need to install ruby rdoc/ri data:
remote:        <= 1.8.6 : unsupported
remote:        = 1.8.7 : gem install rdoc-data; rdoc-data --install
remote:        = 1.9.1 : gem install rdoc-data; rdoc-data --install
remote:        >= 1.9.2 : nothing to do! Yay!
remote:        Bundle completed (27.80s)
remote:        Cleaning up the bundler cache.
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        I, [2016-09-20T19:46:28.469317 #903]  INFO -- : Writing /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/public/assets/application-32aca96fccef5b517f233b349393ff0335e17dd66d613cfc701f61bf0d230635.js
remote:        I, [2016-09-20T19:46:28.469822 #903]  INFO -- : Writing /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/public/assets/application-32aca96fccef5b517f233b349393ff0335e17dd66d613cfc701f61bf0d230635.js.gz
remote:        I, [2016-09-20T19:46:28.499662 #903]  INFO -- : Writing /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/public/assets/application-0723cb9a2dd5a514d954f70e0fe0b89f6f9f1ae3a375c182f43b5f2b57e9c869.css
remote:        I, [2016-09-20T19:46:28.499814 #903]  INFO -- : Writing /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/public/assets/application-0723cb9a2dd5a514d954f70e0fe0b89f6f9f1ae3a375c182f43b5f2b57e9c869.css.gz
remote:        Asset precompilation completed (3.85s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote: ###### WARNING:
remote:        Include 'rails_12factor' gem to enable all platform features
remote:        See for more information.
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.2.4'
remote:        # See for more information.
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote: -----> Rake app detected
remote: rake aborted!
remote: PG::ConnectionBad: could not connect to server: No such file or directory
remote: 	Is the server running locally and accepting
remote: 	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `initialize'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `new'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `connect'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `initialize'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `new'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `postgresql_connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `new_connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `checkout_new_connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `acquire_connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `block in checkout'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `checkout'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `block in connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `retrieve_connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `retrieve_connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `connection'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `initialize'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `new'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `up'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `migrate'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `migrate'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/activerecord- `block (2 levels) in <top (required)>'
remote: /tmp/build_153d6064cc62d6c97ec023b5b72c86c8/vendor/bundle/ruby/2.2.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
remote: Tasks: TOP => db:migrate
remote: (See full trace by running task with --trace)
remote:  !     Push rejected, failed to compile Rake app.
remote:  !     Push failed
remote: Verifying deploy...
remote: !	Push rejected to calm-ridge-11009.
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment