views:

118

answers:

2

I want to protect my database.yml file by keeping it out of version control. Thus, I have two tasks in my Capistrano deploy recipe:

task :copy_db_config do
  # copy local config file if it exists and is more
  # recent than the remote one
end

task :symlink_db_config do
  run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end

Can you help fill in the first task?

A: 

I don't have functioning code for you here and now but..

you can the the local timestamp by using ruby. File class has a function ctime which let's You know when it was changed.

Run the same command on the servers database.yml

If the local one is newest, capistrano has a method for secure upload

upload("products.txt", "/home/medined", :via => :scp)

A: 

I had the same problem, but I approached it differently. Maybe it will be helpful.

The setup task copies database.yml.example to database.yml. The deploy task does not touch database.yml. I have separate tasks for changing the database names, usernames, and passwords. Here's an example:

desc "Change the database name"
task :change_db_database, :roles => :app do
  database = prompt('Enter new database name: ')
  run <<-CMD
    cd #{shared_path}/config &&
    perl -i -pe '$env = $1 if /^(\\w+)/; s/database:.*/database: #{database}/ if $env eq "#{ENV['CONNECTION'] || ENV['TARGET']}"' database.yml
  CMD
end

I run these after setup but before the first deploy on new boxes. Then any time after that when I need to change database parameters, I use these tasks instead of copying in a new file.

Sarah Mei