Search code examples
ruby-on-railsopenshift-enterprise

Database disappearing on OpenShift (OSE) running Postgres and Rails 4 / Ruby 2


I have Ruby (2) on Rails (4) app deployed on OpenShift Enterprise running a Postgres database. After initial deployment the app worked perfectly, information was persisted in the database, routing was working, all the tests were passing - everything was good.

Then I deployed some new changes with git push openshift master. When I went back to the app it was still running, but all the database content (including table structure) was gone.

The output from the push was clean. I didn't write any hooks, or have any funky cron jobs running. I could repeat the process, rebuilding the database, and watch it get blown away on every deployment. This problem was not occurring in my local instance.


Solution

  • tl;dr: Make sure you have a .openshift directory at your project's root, use this as an example: https://github.com/openshift/rails4-example

    Here's what was going on.

    When I created the Rails app I didn't know where I would end up deploying it. Consequently I didn't start with an OpenShift Rails skeleton app or by using rhc app create ruby-X.X.X -a railsX.

    When I was told to deploy on open shift I just configured rhc and set up an openshift git remote.

    This meant there was no .openshift directory in my project's root. Once I cloned https://github.com/openshift/rails4-example and moved that project's .openshift directory into my project root I was able to deploy without losing my database.