Capistrano Deployments
Closed this issue · 2 comments
Hey, does multiverse work with Capistrano?
From what I see in Capistrano here, Capistrano would just runrake db:migrate
for the main db, and not other separate dbs.
Here's one possible solution, which is what my team did initially:
https://www.reddit.com/r/rails/comments/53tdob/possible_for_capistrano_to_migrate_multiple/
We override the default db:rake
tasks so that Capistrano will pick up and migrate all 3 databases, and we had manually switch ActiveRecord connection based on our ENVs.
That worked, but that sort of defeats the purpose of multiverse
's version of migration (DB=another_db bundle exec rake db:migrate
). It also doesn't generate a schemas for us if we do it that way (I could probably invoke a db:schema:dump
though).
This seems like a Capistrano problem (I can maybe just add a hook to Cap and manually run my rake?), but since it relates to multiverse in a way I'm throwing it out here to see what you folks think.
Hey @edisonywh, I haven't used Capistrano for a long time, but seems like the cleanest way would be to add a hook to run the tasks manually.
DB=another_db bundle exec rake db:migrate
If you already have something working, I don't think there's a strong reason to change it.
We needed to change it because the way we hacked it didn't allow for schema generations (though to be fair, could've explored the schema:dump
option. We also didn't feel comfortable overriding the default behavior upon revisiting (might confuse new developers too).
I've got it working like so in case anyone else is wondering:
# deploy.rb
after :migrate, 'db:migrate:others' (check out hooks that you can hook into here https://capistranorb.com/documentation/getting-started/flow/)
# lib/capistrano/tasks/db.rake
namespace :db do
namespace :migrate do
task :others do
on roles(:db) do
within release_path do
with rails_env: fetch(:rails_env) do
["db_1", "db_2"].each do |db|
puts "Migrating #{db} database"
execute :rake, "db:migrate DB=#{db}"
end
end
end
end
end
end
end
Sidenote: Opted not to use ``/system
to run, because it seems like it'll attempt to run it on my local machine.
Thanks for your help anyway! @ankane Great work with the gem :)