I am also new to Capistrano and am trying to use it for the first time to deploy a Rails application to production servers configured using Puppet.
I finally had to break into the source of Capistrano (and capistrano / bundler, and capistrano / rails, and even sshkit and net-ssh to debug auth problems) to pinpoint how everything works before I felt that the trustee decide what changes I wanted to make. I just finished these changes and I am pleased with the results:
# lib/capistrano/tasks/cold.rake namespace :deploy do desc "deploy app for the first time (expects pre-created but empty DB)" task :cold do before 'deploy:migrate', 'deploy:initdb' invoke 'deploy' end desc "initialize a brand-new database (db:schema:load, db:seed)" task :initdb do on primary :web do |host| within release_path do if test(:psql, 'portal_production -c "SELECT table_name FROM information_schema.tables WHERE table_schema=\'public\' AND table_type=\'BASE TABLE\';"|grep schema_migrations') puts '*** THE PRODUCTION DATABASE IS ALREADY INITIALIZED, YOU IDIOT! ***' else execute :rake, 'db:schema:load' execute :rake, 'db:seed' end end end end end
The deploy: cold task simply captures my own deployment: the inidb task to run before deployment: migrate. Thus, the schema and seeds are loaded, and the deploy: migrate step that follows does nothing (safe), because there are no new migrations to run. As a safety measure, I check if the schema_migrations table exists before loading the schema if the deployment starts: it's cold again.
Note. I choose to create the database using Puppet, so I can avoid giving the CREATEDB privilege to my postgresql user for production, but if you want Capistrano to do this, just add "execute: rake, db: create", "before db: schema: load or replace all three lines with "db: setup".
odigity
source share