R – Capistrano Deploy Wipes Database

capistranodatabasedeploymentruby-on-railssvn

I've managed to deploy my app to production using Capistrano, but I don't understand how to deal with my database. I'm using subversion and passenger.

When I run cap deploy, the new deployment starts everything fresh. It wipes out the data that was added to the database. Obviously, there must be a solution, but I'm very surprised not to find anything online about how to deal with this. I've read the Capistrano documentation and many tutorials.

The best I can find is the Advanced Rails recipes books, which talks about putting user-generated content into the shared directory, but it's not exactly on point.

How do you deal with your database when deploying with Capistrano?

Best Answer

Chances are you are using SQLite, and you are keeping the database in the default location. Your database is not being deleted, more just left behind.

You need to edit your database.yml and tell it to keep your production database in a shared location "../../shared/database.yml" or similar (you may be better off using an absolute path, or for bonus points MySQL).

When you deploy via capistrano it creates a new copy of your app in a timestamped directory. Your database is being left behind in the old timestamped dir.

Related Topic