2014-11-04 90 views
1

我使用capistrano將我的Rails應用程序部署到我的VPS,但每次部署後,當我訪問我的頁面時出現錯誤。日誌說:Capistrano部署刪除表

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' 

我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, '[email protected]: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 

那麼,爲什麼Capistrano的刪除我的數據庫,當我部署?

回答

4

Capistrano不會觸摸數據庫遷移,除非您在Capfile內的deploy:migrate任務或通過撥打bundle exec cap deploy:migrate指定了該任務。

您的數據庫'消失',因爲SQLite只是您的db目錄中的一個文件。由於您沒有指定它應該在版本之間共享(在shared目錄中),它只會消失並保留在以前的版本中。將db/production.sqlite3添加到您的linked_files聲明中。

+0

你是對的。我剛剛檢查了部署的輸出,在那裏找不到任何東西,引起了'rake migrate'或'rake create'。但是它在部署之後發生,所以出了問題。 – 2014-11-04 14:36:55

+0

我已更新我的答案 – blelump 2014-11-04 14:43:36

+0

使得sence,但是當我現在運行它時,我得到了顯而易見的錯誤'/home/deploy/movieseat/shared/db/production.sqlite3不會激發'。但只是將sqlite文件放在那裏不會有太大的作用,因爲應用程序沒有引用使用共享sqlite文件而不是db文件夾中的on。 – 2014-11-04 14:51:17