在生产模式下迁移的麻烦

时间:2011-10-26 12:15:51

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 capistrano

我正在使用Ruby on Rails 3.1.0和Capistrano gem,我创建了一个迁移文件,以便更改数据库表列名。在我的本地计算机上运行rake db:migrate命令(在development模式下)它可以工作,但我想在production模式下在远程服务器上进行这些更改。 我的问题是如果我运行Capistrano命令cap deploy:migrate我在远程服务器上的生产日志文件中收到以下错误消息

* executing "cd /<my_application_path>/releases/20111025205951 && rake RAILS_ENV=production  db:migrate"
  servers: ["<my_application_IP>"]
  [<my_application_IP>] executing command
 ** [out :: <my_remote_server_IP>] (in /<my_application_path>/releases/20111025205951)
*** [err :: <my_remote_server_IP>] rake aborted!
*** [err :: <my_remote_server_IP>] uninitialized constant Rake::DSL
*** /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
*** ...

如何解决问题?是否与使用上述错误消息中输出的Ruby版本1.9.1有关?


注意:如果我运行ruby -v命令

# on the local machine (MacOS running Snow Leopard 10.6.7) I get
>> ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.7.0]
# on the remote machine (Linux running Ubuntu 10.04 LTS) I get
>> ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

@Simone Carletti的

更新

我在require 'bundler/capistrano'文件的顶部添加deploy.rb后,在运行cap deploy:migrations命令后,出现以下错误:

...
* executing "cd /<my_application_path>/releases/20111026132212 && bundle install --gemfile /<my_application_path>/releases/20111026132212/Gemfile --path /<my_application_path>/shared/bundle --deployment --quiet --without development test"
  servers: ["<my_remote_server_IP>"]
  [<my_remote_server_IP>] executing command
** [out :: <my_remote_server_IP>] Some gems seem to be missing from your vendor/cache directory.
** [out :: <my_remote_server_IP>] Could not find libv8-3.3.10.2 in any of the sources
   command finished in 2554ms
failed: "sh -c 'cd /<my_application_path>/releases/20111026132212 && bundle install --gemfile /<my_application_path>/releases/20111026132212/Gemfile --path /<my_application_path>/shared/bundle --deployment --quiet --without development test'" on <my_remote_server_IP>

这是什么意思?它可能与以下文字的最后一部分(即N.B.部分)有关?如果是这样,我该怎么做?

当我运行cap -e bundle:install命令(来自official documentation)时,我得到:

------------------------------------------------------------
cap bundle:install
------------------------------------------------------------
Install the current Bundler environment. By default, gems will be installed to
the shared/bundle path. Gems in the development and test group will not be
installed. The install command is executed with the --deployment and --quiet
flags. If the bundle cmd cannot be found then you can override the bundle_cmd
variable to specifiy which one it should use.

You can override any of these defaults by setting the variables shown below.

N.B. bundle_roles must be defined before you require 'bundler/capistrano' in
your deploy.rb file.

  set :bundle_gemfile,  "Gemfile"
  set :bundle_dir,      File.join(fetch(:shared_path), 'bundle')
  set :bundle_flags,    "--deployment --quiet"
  set :bundle_without,  [:development, :test]
  set :bundle_cmd,      "bundle" # e.g. "/opt/ruby/bin/bundle"
  set :bundle_roles,    {:except => {:no_release => true}} # e.g. [:app, :batch]

注意cap deploy:migrations命令创建了一个空的/<my_application_path>/shared/bundle/ruby/1.9.1目录,其中755个省略。

1 个答案:

答案 0 :(得分:0)

这是有罪的。

rake RAILS_ENV=production  db:migrate

你应该运行

bundle exec rake RAILS_ENV=production  db:migrate

确保在bundler/capistrano文件中加入deploy.rb食谱。

require 'bundler/capistrano'

这些食谱将为您更改命令。请参阅Automatic deployment with Capistrano