因此,我在使用 rails(ruby 1.9.3p392、rails 3.2、sqlite3 db),并且正在尝试将无处不在的博客教程代码部署到“生产”服务器(apache、passenger、ubuntu)。我的 deploy.rb 看起来像这样:
require 'bundler/capistrano'
require 'rvm/capistrano'
load 'deploy/assets'
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
set :rvm_type, :user
set :user, 'blah'
set :application, 'railsTest'
set :domain, 'www.blah.com'
set :applicationdir, "/home/sean/public/blah.com/public"
set :scm, 'git'
set :repository, "ssh://blah@1.1.1.1/home/blah/public/bla.com/public/capDep.git"
#set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
set :migrate_target, :latest
# additional settings
default_run_options[:pty] = true # Forgo errors when deploying from windows
#ssh_options[:keys] = %w(/home/blah/.ssh/id_rsa)
ssh_options[:forward_agent] = true
# if you want to clean up old releases on each deploy uncomment this:
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
#after "deploy:update_code", "deploy:migrate"
现在,我敢肯定,对于那些知道他们在用 capistrano 做什么的人来说,这看起来一定是一团糟,但我是个彻头彻尾的笨蛋。最后,尽管我的不足,部署似乎工作,因为当我运行以下
cap deploy:setup
cap deploy
我的应用程序已启动并正在运行,因为我可以,我通过 rails 为我创建的 web ui 在数据库中的表中添加了几行。现在,我变得粗体并创建一个迁移,向表中添加一列。我将更改推送到 git。令我恐惧的是,当我跑步时
cap deploy
运行所有迁移,这会重新创建表,从而破坏我的所有数据。我已经多次重复这个痛苦的过程。我的 schema_migrations 表如下所示:
20130620210004
20130620220229
20130628213331
20130628214946
20130628223002
我在这里想念什么?
更新: 我最近给出了@TheMahrvin 关于在命令行运行 deploy:migrations 并将其从 deploy.rb 中删除的建议。它没有用......再一次,所有迁移都运行了。我的缪斯一定在我耳边耳语了些什么,因为我决定尝试在服务器本身上运行 db:migrate。在运行“rake”后看到这个输出我很惊讶:
20130717230110 CreateHighScores
20130717230342 CreateGames
20130717231041 AddGameTypeToGame
20130717233707 AddGamePublisherToGame
20130717234124 AddGameRatingToGame
20130731210558 AddGameMechanicToGame
只有最后的迁移应该是挂起的。所以,也许这根本不是 Capistrano 的问题(我已经更新了这个问题的标题以反映这一点)。那么,为什么之前的迁移仍被标记为待处理?我知道它们过去曾运行过,因为我在输出中看到了它们并在它们运行后验证了数据库模式。
更新#2: 设置另一个迁移并ssh'd进入服务器并cd'd进入“当前”目录,如果我完全理解capistrano(很大机会)就是当前文件所在的位置。跑步
bundle exec rake db:migrate:status
得到了我:
Status Migration ID Migration Name
--------------------------------------------------
down 20130717230110 Create high scores
down 20130717230342 Create games
down 20130717231041 Add game type to game
down 20130717233707 Add game publisher to game
down 20130717234124 Add game rating to game
down 20130731210558 Add game mechanic to game
down 20130731212454 Add publish year to game
down 20130731214515 Add game rank to game
down 20130731214928 Add game abbr to game
down 20130731215749 Add crazy field to game
我不禁感到我正在尝试做的事情有什么严重的错误。