使用 Nginx Capistrano Rake db:Migrate

Rake db:Migrate with Nginx Capistrano

我是 运行 一台使用 Nginx、Capistrano、Rails

的服务器

我在我的本地机器上做了一些db:migrations,然后想把它们推送到我的服务器上。但是我不知道如何在服务器上迁移我的数据库。我该怎么做?

我试过了

1)

cap production deploy
cap production deploy:migrate

2)

[On server - in current]
rake db:migrate

但其中 none 似乎有效。我如何进行迁移?

Capistrano 文件

lock '3.4.0'
 require 'capistrano/sidekiq'
 set :whenever_command, "bundle exec whenever"
 require "whenever/capistrano"
set :application, 'myApp'
set :repo_url, 'git...'
set :keep_releases, 5
set :scm, :git
set :repository, "git..."
set :scm_passphrase, "..."
set :user, "..."
set :use_sudo, false
set :deploy_to, "/.../.../apps/appName"
namespace :deploy do
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
    end
  end
end

1) 如果你使用的是 capistrano-rails 你应该设置

set :migration_role, 'migrator'            # Defaults to 'db'

2) 在您正在开发环境中进行迁移的服务器上,尝试

RAILS_ENV=production bundle exec rails db:migrate

要使用 capistrano 进行 运行 迁移,在位于 /config/deploy 中的 production.rb 文件上添加 "db" 角色 例如

roles: %w{web app db}

如果 current_pathrelease_path 迁移之间存在差异,capistrano 迁移任务也可以工作。您可以做的是从 current_path 内部删除迁移,然后部署,然后迁移。