-
Notifications
You must be signed in to change notification settings - Fork 7
Deploy with Capistrano
Henrique Gubert edited this page Nov 22, 2016
·
2 revisions
capistrano-rails will automatically migrate your database for you, but it will not create/migrate shards for you.
If you want to deploy a sharded application you can add the following task to your deploy recipe:
namespace :deploy do
namespace :shards do
desc 'Ensures all shards are created and migrated'
task :ensure_created_and_migrated => [:set_rails_env] do
on primary fetch(:migration_role) do
within release_path do
with rails_env: fetch(:rails_env) do
info '[deploy:shards:ensure_created_and_migrated] Run `rake shards:create`'
execute :rake, 'shards:create'
info '[deploy:shards:ensure_created_and_migrated] Run `rake shards:migrate`'
execute :rake, 'shards:migrate'
end
end
end
end
end
after 'deploy:updated', 'deploy:shards:ensure_created_and_migrated'
end
This task will create the non-existing shards for you, and migrate all shards of all groups on deploy.
You will also need to add your config/shards.yml
to the list of linked files on you recipe, and remember to create the config file on your production server before the deploy.
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'config/shards.yml')