Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7897 (closed defect: wontfix)

Opened 3 years ago

Last modified 3 years ago

deploy_with_migrations should call before_deploy hook and after_deploy hook, but does not

Reported by: louielouie Assigned to: minam
Priority: normal Milestone: 1.x
Component: Capistrano Version: edge
Severity: normal Keywords: 1.4.1 deploy_with_migrations before_deploy
Cc:

Description

I have a Capistrano recipe that declares a before_deploy task to perform some backups before a deploy occurs for a Rails app that will go into production soon.

This works fine when I execute "cap deploy", but does not execute at all if I do "cap deploy_with_migrations". I think that it should execute, as should an after_deploy task if it is defined. The reason is because they do almost the same thing, except there is migrations involved in the middle of the latter. If you know you don't need to do a migration, you can just run "cap deploy" and if you do, then you can run "cap deploy_with_migrations" and that should be the only difference. I looked in Capistrano Edge and saw "deploy_with_niftiness" which is a good hypothetical where I think before_deploy/after_deploy should also be executed.

Paul Goscicki blogged about encountering the same problem and expecting the same behavior at http://paulgoscicki.com/archives/2007/02/late-night-capistrano/

I looked at the capistrano source code and can think of a few ways to fix this:

1. Put a patch into actor.define_task to look explicitly for name == "deploy_with_migrations" and in that specific case, send "before_deploy" and "after_deploy". What it will do now is "before_deploy_with_migrations" and "after_deploy_with_migrations".

2. Do the same patch, but look for anything that matches "foo_with_bar". That could be a convention that means it is almost the same as foo, but slightly different and so "before_foo" and "after_foo" should be called.

3. Change standard.rb to put in an explicit call to before_deploy and after_deploy in deploy_with_migrations task.

I've already made a patch doing it way 1, but it seems like way 2 would be the most elegant. Way 3 seems to break the spirit of the before/after hooks.

Change History

05/11/07 03:48:35 changed by minam

  • status changed from new to closed.
  • resolution set to wontfix.

Actually, what you want is to not put the hooks on deploy, but on something like update_code, which is called whether you do deploy or deploy_with_migrations. Or, put your backup code in your own tasks, and then define both before_deploy and before_deploy_with_migrations, and have those simply call your custom tasks.

Cap2 will have a nice, clean way of doing that:

  before :deploy, :run_backups
  before "deploy:migrations", :run_backups

  task :run_backups do
    # ...
  end