所以,我正在围着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"
现在,我相信,那些知道他们在做什么的人,看起来就像一个很大的混乱,但我是一个完美的混蛋.最后,尽管我的不足之处,部署似乎正常,因为当我运行以下操作
cap deploy:setup cap deploy
我的应用程序正在运行,只是因为我可以通过rails为我创建的web ui在数据库中的表中添加几行.现在,我得到大胆的创建一个迁移,添加一个列到一个表.我把我的更改推送到git.对我的恐惧,当我跑
cap deploy
所有迁移都会运行,这会重新创建表,从而破坏了我的所有数据.我多次重复了这个痛苦的过程.我的schema_migrations表如下所示:
20130620210004 20130620220229 20130628213331 20130628214946 20130628223002
我在这里缺少什么?
更新:我最近给了@Mahrvin关于在命令行上运行deploy:migrations并将其从deploy.rb中删除的建议.它没有工作…再次,所有的迁移都运行.我的缪斯必须在我耳边低语,因为我决定尝试在服务器本身上运行db:migrate.在“rake”运行后,我很惊讶地看到这个输出:
20130717230110 CreateHighscores 20130717230342 CreateGames 20130717231041 AddGameTypeToGame 20130717233707 AddGamePublisherToGame 20130717234124 AddGameRatingToGame 20130731210558 AddGameMechanicToGame
只有最后的迁移应该等待.所以,或许这不是Capistrano的问题(我更新了这个问题的标题来反映出来).那么,为什么以前的迁移仍然被标记为待处理?我知道他们是过去运行的,因为我看到它们在输出中,并且在运行后验证了数据库模式.
更新#2:设置另一个迁移和ssh进入服务器,并cd我的方式到“当前”目录,如果我明白capistrano(fat几率)是当前文件的位置.运行
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
我不禁感到,我正在努力做什么有深刻的错误.