Capistrano 3 is not running rails migrations when deployed

Francesco Zaffaroni picture Francesco Zaffaroni · Mar 23, 2014 · Viewed 14.3k times · Source

I want to deploy to production an app to my local server. i'm using capistrano 3.

this is my capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
#require 'capistrano/rails/migrations'
#require 'capistrano/rails/assets'


# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

this is my deploy.rb

# config valid only for Capistrano 3.1
lock '3.1.0'

set :application, 'ImpresaZiliani'
set :repo_url, '[email protected]:repos/impresaziliani.git'
set :branch, 'master'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/francesco/impresaziliani'

# Default value for :scm is :git
set :scm, :git
set :deploy_user, "francesco"
set :rails_env, "production"

set :keep_releases, 5

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
   end
  end

end

set :rvm_ruby_version, '2.1.1'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#                   {fetch(:rvm_ruby_version)} do bundle exec rake"

my database.yml is ok since if i run manually the migrations on the server it works, i have tried with uncommenting the line of capistrano/rails/migrations and assets but nothing changes: when i deploy it runs fine till the bundler install, then without any warning or error, skip to the asset precompiler and doesn't run migrations.

how can i fix this?

thank you

Answer

aquajach picture aquajach · Dec 28, 2014

You also need to make the user deploying has the role of db, such as:

server 'you_ip_address', user: 'user_name', roles: %w{web app db}