Pet*_*sma 1 deployment capistrano ruby-on-rails
我使用 capistrano 将 Rails 应用程序部署到我的 VPS,但每次部署后,当我访问我的页面时,我都会收到错误。日志说:
I, [2014-11-04T08:20:16.659289 #12482] INFO -- : Started GET "/" for 82.73.170.71 at 2014-11-04 08:20:16 -0500
I, [2014-11-04T08:20:16.662717 #12482] INFO -- : Processing by HomeController#index as HTML
I, [2014-11-04T08:20:16.665979 #12482] INFO -- : Completed 500 Internal Server Error in 3ms
F, [2014-11-04T08:20:16.670152 #12482] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'users'):
app/controllers/application_controller.rb:18:in `current_user'
app/helpers/sessions_helper.rb:26:in `logged_in?'
app/controllers/home_controller.rb:4:in `index'
Run Code Online (Sandbox Code Playgroud)
我必须 ssh 进入我的 VPS 并转到我的 Rails 根目录并运行RAILS_ENV=production bundle exec rake db:migrate. 在我的 db 文件夹中,我仍然有该production.sqlite3文件,但它是空的。
我的deploy.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'movieseat'
set :repo_url, 'git@github.com:alucardu/movieseat.git'
set :deploy_to, '/home/deploy/movieseat'
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
require 'capistrano-rbenv'
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
Run Code Online (Sandbox Code Playgroud)
那么为什么 Capistrano 在我部署时会删除我的数据库呢?
Capistrano 不会触及数据库迁移,除非它是由deploy:migrate您的任务指定的Capfile或通过调用bundle exec cap deploy:migrate.
您的数据库“消失”了,因为 SQLite 只是您db目录中的一个文件。由于您没有指定它应该在版本之间共享(在shared目录内),那么它就会消失并保留在以前的版本中。添加db/production.sqlite3到您的linked_files声明中。