This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Setting up your database is something that's unique to your app. It's not practical for Capistrano to do for you by default. You need to provide a task to create the database. If we were doing it manually, we'd change into the app directory and running "rails db:setup" in the "production" environment. We need to create a Capistrano task to do the same thing.
Add the following code to lib/capistrano/tasks/deploy_initial.rake
:
namespace :deploy do
desc "Performs first deploy to a server"
task :initial do
before "deploy:migrate", "deploy:create_db"
invoke "deploy"
end
desc "Runs rails db:setup"
task :create_db do
on roles(:db) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rails, "db:setup"
end
end
end
end
end
The task can then be run with bundle exec cap production deploy:initial
.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up