Quite often in #capistrano recipes I see running migrations and assets precompilation on each deploy which I think is not what you want because it takes time and if there is no new migrations or assets its time is spent in vain. In this post I will show you a script which is used in #gistflow to skip #migrations.

namespace :db_migrations do
  task :migrate do
    from = source.next_revision(current_revision)
    if capture("cd #{latest_release} && #{source.local.log(from)} db/migrate | wc -l").to_i > 0
      run "cd #{current_release} && RAILS_ENV=#{rails_env} bundle exec rake db:migrate"
      logger.info "New migrations added - running migrations."
    else
      logger.info "Skipping migrations - there are not any new."
    end
  end
end

The source could be found in gistflow's deploy.rb

Soon I will make the same thing for assets, make it DRY and opensource.