Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Capistrano deploy:migrate和db:migrate每次都运行所有迁移大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以,我正在围着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

所有迁移都会运行,这会重新创建表,从而破坏了我的所有数据.我多次重复了这个痛苦的过程.我的scheR_571_11845@a_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

我不禁感到,我正在努力做什么有深刻的错误.

解决方法

我没看过:
after "deploy:update_code","deploy:migrate"

之前.尝试删除该行并运行:

bundle exec cap deploy:migrations (deploys code and migrations)

要么

bundle exec cap deploy:migrate (runs the migrate rake task on the server)

代替.其余的deploy.rb似乎对我来说很好,然我不知道有关rvm / capistrano集成或Windows调整的任何内容.

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – Capistrano deploy:migrate和db:migrate每次都运行所有迁移全部内容,希望文章能够帮你解决ruby-on-rails – Capistrano deploy:migrate和db:migrate每次都运行所有迁移所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。