Capistrano - how do I set up the database config?

My app is set up without database.yml in version control. I created a
shared_path/config dir, and put database.yml in it. After I update
the code, I want to link the app’s database.yml file to the shared
config. So I added this task

desc ‘Copy the database config’
task :after_update_code, :roles => :app do
run “ln -s #{shared_path}/config/database.yml
#{current_path}/config/database.yml”
end

Unfortunately that doesnt work, because update_code is in a
transaction, so current_path points to the app that’s currently
running, rather than the most recently checked out code version. So I
get the following error:

  • executing task after_update_code
  • executing “ln -s ~/apps/blog/shared/config/database.yml
    ~/apps/blog/current/config/database.yml”
    servers: [“www.mydomain.com”]
    [www.mydomain.com] executing command
    ** [out :: www.mydomain.com] ln:
    /home/pergesu/apps/blog/current/config/database.yml: File exists
    command finished
    rake aborted!
    command “ln -s ~/apps/blog/shared/config/database.yml
    ~/apps/blog/current/config/database.yml” failed on www.mydomain.com

In the past I’ve put the ln in the restart task, but that’s an ugly
hack, plus it doesn’t allow me to “rake remote:restart” - the file
already exists, so it fails. I have to do a full deploy just to
restart it. So how do I do what I want?

Finally, I have a question about running migrations. Does rake deploy
just do remote:update_code and remote:restart? Or does it do other
stuff? If I need to run migrations, it’d be best if I can update the
code, run migrations, and restart the app. “rake remote:update_code;
rake remote:migrate; rake remote:restart”, instead of what I’m
currently doing now chich is “rake deploy; rake remote:migrate; rake
remote:restart”

Thanks for any info.

Pat

Pat,

I’m afraid I can’t help with your other issues, but there is a
“deploy_with_migrations” task in the remote namespace.

rake remote:deploy_with_migrations

Jeff

Pat M. wrote:

My app is set up without database.yml in version control. I created a
shared_path/config dir, and put database.yml in it. After I update
the code, I want to link the app’s database.yml file to the shared
config. So I added this task

desc ‘Copy the database config’
task :after_update_code, :roles => :app do
run “ln -s #{shared_path}/config/database.yml
#{current_path}/config/database.yml”
end

Unfortunately that doesnt work, because update_code is in a
transaction, so current_path points to the app that’s currently
running, rather than the most recently checked out code version. So I
get the following error:

  • executing task after_update_code
  • executing “ln -s ~/apps/blog/shared/config/database.yml
    ~/apps/blog/current/config/database.yml”
    servers: [“www.mydomain.com”]
    [www.mydomain.com] executing command
    ** [out :: www.mydomain.com] ln:
    /home/pergesu/apps/blog/current/config/database.yml: File exists
    command finished
    rake aborted!
    command “ln -s ~/apps/blog/shared/config/database.yml
    ~/apps/blog/current/config/database.yml” failed on www.mydomain.com

In the past I’ve put the ln in the restart task, but that’s an ugly
hack, plus it doesn’t allow me to “rake remote:restart” - the file
already exists, so it fails. I have to do a full deploy just to
restart it. So how do I do what I want?

Finally, I have a question about running migrations. Does rake deploy
just do remote:update_code and remote:restart? Or does it do other
stuff? If I need to run migrations, it’d be best if I can update the
code, run migrations, and restart the app. “rake remote:update_code;
rake remote:migrate; rake remote:restart”, instead of what I’m
currently doing now chich is “rake deploy; rake remote:migrate; rake
remote:restart”

Thanks for any info.

Pat

Hey Jeff,

Thanks for the tip on deploy_with_migrations

I found out that I need to use release_path instead of current_path
inside after_update_code, because update_code doesn’t do any
symlinking. release_path is the path to the release that’s being
checked out.

Pat

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs