Sunday, September 6, 2015

How to deploy a PostgreSQL database in Ruby on Rails through Cloud Foundry

If you have a Ruby on Rails app with a PostgreSQL database and you are deploying it for the first time through Cloud Foundry to your hosting provider, you might have realized that a simple cf push yourappname doesn't initialize the database.
As it occurs when you are working locally, you first need to trigger the database creation and migration processes.

In my case, I am connecting to IBM Bluemix through Cloud Foundry, and my app is connected to an ElephantSQL PostgreSQL database. These are the steps to deploy my app successfully:

1) Deploy the app for the first time: cf push yourappname
2) Create the database and run the migrations (if any): cf push -c "bundle exec rake db:create db:migrate" yourappnameNote that this command will leave the app down.
3) Start the app again: cf push -c "null" yourappname

No comments:

Post a Comment