Skip to content

Instantly share code, notes, and snippets.

@freegenie
Created January 23, 2013 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freegenie/4610250 to your computer and use it in GitHub Desktop.
Save freegenie/4610250 to your computer and use it in GitHub Desktop.
Snipped of code to finally have capistrano run db:schema:load on cold deploys. Paste this in your capistrano recipe.
namespace :deploy do
task :load_schema, :roles => :db, :only => { :primary => true } do
rake = fetch(:rake, "rake")
rails_env = fetch(:rails_env, "production")
migrate_env = fetch(:migrate_env, "")
migrate_target = fetch(:migrate_target, :latest)
directory = case migrate_target.to_sym
when :current then current_path
when :latest then latest_release
else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
end
run "cd #{directory} && #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:schema:load"
end
task :cold do
update_code
load_schema
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment