Title: A Capistrano Task To Sync The Database Config File Date: 21 August 2011 URL: https://ralovely.com/blog/2011/08/21/capistrano-update-database-config/ Author: Raphael Campardou Archived: yes --- This is an old post, kept here for posterity. Some links may be broken, opinions may have changed, and technology has certainly moved on. --- For the railers out there, here is a Capistrano task to keep your server database config in sync with what's on your local machine. It's common knowledge: you don't check-in your database file in your repository because it contains your password. One usually puts it in the shared directory after the deploy:setup command was run, and it is copied at each deploy. But because we're so used to having the deploy command updating each and every file, and because the database.yml file isn't updated often, you can, as I did, ruin two hours, wondering why your Passenger asks for mysql2 even if you have changed your database file accordingly. But locally... It won't happen anymore. I wrote a Capistrano task that rsync the local database file to the shared/config directory before each deploy. Put that in your deploy.rb file, inside the deploy namespace. ```ruby desc "Update remote database file with local copy" task :update_database_config do run_locally("rsync --times --rsh=ssh --compress --human-readable --progress config/database.yml #{user}@#{domain}:#{shared_path}/config/database.yml") end ``` and this at the end of the file ```ruby before "deploy:update_code", "deploy:update_database_config" ``` --- For the humans reading the machine-readable version: hello. You're thorough. I appreciate that.