将Rails从4.2升级到5.2依赖项

时间:2018-11-08 09:49:31

标签: ruby-on-rails ruby-on-rails-4 activerecord ruby-on-rails-5

我第一次进行此升级,而我在第一步中就遇到了问题:-(

基本上,我想升级项目的Rails版本,所以我更改了Rails 5.2的Gemfile并尝试运行:

bundle update rails

here给出,但我无法更新包并收到以下错误

Bundler could not find compatible versions for gem "activerecord":
  In Gemfile:
    rails (~> 5.2) was resolved to 5.2.1.rc1, which depends on
      activerecord (= 5.2.1.rc1)

    schema_plus_views was resolved to 0.3.1, which depends on
      activerecord (~> 4.2)

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (~> 5.2)

    gaffe was resolved to 1.2.0, which depends on
      rails (>= 4.0.0)

    rails_admin was resolved to 1.3.0, which depends on
      rails (< 6, >= 4.0)

    rails_admin_globalize_field was resolved to 0.4.0, which depends on
      rails (>= 4.2)

    sql-logging was resolved to 3.0.10, which depends on
      rails (>= 4.0)

Bundler could not find compatible versions for gem "rake":
  In Gemfile:
    rake (~> 11.2)

    capistrano (~> 3.6) was resolved to 3.11.0, which depends on
      rake (>= 10.0.0)

    derailed_benchmarks was resolved to 1.3.2, which depends on
      rake (< 13, > 10)

我的宝石文件是

source 'https://rubygems.org'

gem 'pg', platform: :ruby
gem 'schema_plus_views'
gem 'fix-db-schema-conflicts', github: 'davidlibrera/fix-db-schema-conflicts'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rake', '~> 11.2'
gem 'rails', '~> 4.2'
# gem 'rb-readline'
# Use postgresql as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails'
gem "less-rails", platform: :ruby #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'
gem "typescript-rails"
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem "bootstrap-sass"
gem "font-awesome-rails"
gem 'haml'

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem "bower-rails"
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'oj'
gem 'jbuilder'
gem 'angular-rails-templates'
gem 'gaffe'
gem 'color-generator'

# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1'

# we have keep redis client below version 4 until this issue is solved
# https://github.com/antirez/redis/issues/4272
# and we have to keep redis below 3.3.2 until this issue is solved
# https://github.com/redis/redis-rb/issues/650
gem 'redis', '3.3.5', require: %w(redis redis/connection/hiredis)
gem 'hiredis'
gem 'puma'
gem 'puma_worker_killer'
gem "dalli"
gem 'jbuilder_cache_multi'
gem 'globalize', '~> 5.0'
gem 'rack-attack'
gem 'ya2yaml'
gem 'cells-rails'
gem 'cells-erb'

# gem 'highline'
gem 'kaminari'
gem 'nokogiri'

gem 'zss', git: "https://github.com/ISEngineering/zmq-service-suite-ruby", platform: :ruby
gem 'ffi-rzmq', '2.0.4'

gem 'therubyracer'
gem "paperclip", "~> 4.3"
gem 'bootstrap-wysihtml5-rails'
gem 'rails-i18n', '~> 4.0'

# Excel depdendencies
gem 'xlsxtream', '>= 2'

# Excel legacy export
gem 'axlsx_rails', '0.5.1'
gem 'axlsx', git: 'https://github.com/randym/axlsx.git'
gem 'rubyzip', '>= 1.2.1'
gem 'zip-zip'

gem 'devise', '~> 4.2'
gem 'devise-i18n'
gem 'savon', '~> 2.10'

gem 'party_foul', git: 'https://github.com/alexanderadam/party_foul.git', branch: 'bugfix/132-dont-assume-that-exceptions-have-a-backtrace' #'>= 1.5.5'

gem 'ledermann-rails-settings'
gem 'dentaku'
gem 'delayed_job_active_record'
gem 'cancancan'
gem 'rolify'
gem 'rails_admin'
gem 'enumerize'
gem 'rails_admin_settings'
gem 'rails_admin_globalize_field'
gem 'trailblazer-rails'
gem 'premailer-rails'
gem 'bulk_insert'

# for assets that are referenced by libraries in vendor/assets
gem 'non-stupid-digest-assets'

gem 'actionpack-action_caching'
gem 'dotenv-rails'

group :development, :test do
  gem 'database_cleaner'
  gem 'rspec-rails'
  gem 'pry'
  gem 'pry-nav'
  gem 'awesome_print'
  gem 'mocha'
  gem 'webmock' # for vcr
  gem 'vcr'
  gem 'chromedriver-helper', '>= 2.1.0'
  gem 'selenium-webdriver', '3.9.0'
  gem 'capybara'
end

group :test do
  gem 'factory_bot_rails'
  gem 'db-query-matchers'
  gem 'capybara-screenshot'
  gem 'fakeredis',  require: 'fakeredis/rspec'
end

group :development do
  gem 'i18n-tasks'
  gem 'spring'
  gem 'letter_opener'
  gem 'derailed_benchmarks'
  gem 'sql-logging'
  gem 'rubocop'
  gem 'rubocop-rspec'
  gem 'fasterer'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'activerecord-colored_log_subscriber' # this won't be required with rails 5 anymore

  # Use Capistrano for deployment
  gem 'capistrano',  '~> 3.6'
  gem 'capistrano-rbenv', '~> 2.0'
  gem 'capistrano-bundler', '~> 1.1.2'
  gem 'capistrano-rails'
  gem 'capistrano3-puma', github: "seuros/capistrano-puma"
  gem 'capistrano3-delayed-job', '~> 1.0'

end

group :profile do
  gem 'ruby-prof'
end

gem 'sdoc', group: :doc
gem 'sshkit' # is needed to load tasks on server

我该怎么办?

2 个答案:

答案 0 :(得分:2)

首先,正如ThorTL67在评论中指出的那样,一个好主意是逐步升级Rails版本,而不是一个大的飞跃。这样,您的依赖性问题就不会那么复杂了。

通过运行Bundler来检查使用的bundle version版本。如果该版本较旧,则可能是某些依赖关系未正确计算,这可能有助于更新Bundler(gem update bundler)。

然后执行从4.2更新到“更高版本”的步骤。您得到的错误列表显示了gem依赖项之间的冲突。您可以尝试一一解决这些冲突。

Bundler could not find compatible versions for gem "activerecord":
  In Gemfile:
    rails (~> 5.2) was resolved to 5.2.1.rc1, which depends on
      activerecord (= 5.2.1.rc1)

    schema_plus_views was resolved to 0.3.1, which depends on
      activerecord (~> 4.2)

此错误非常简单。它告诉您gem rails需要activerecord v5.2.1,但是gem schema_plus_views需要activerecord> = 4.2.0但<5.0(请参阅RubyGems {{3} }。那么如何解决呢?如果检查schema_plus_views的源页面,则会看到activerecord v5.2.1尚无兼容版本,并且不太可能很快出现:explanation of constraints

因此,在这种情况下,您有几个选择。将其保留在Gemfile中,并从代码中删除对此gem的依赖;检查可为您提供所需功能的替代宝石;帮助更新gem以支持Rails 5。

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (~> 5.2)

    gaffe was resolved to 1.2.0, which depends on
      rails (>= 4.0.0)

    rails_admin was resolved to 1.3.0, which depends on
      rails (< 6, >= 4.0)

    rails_admin_globalize_field was resolved to 0.4.0, which depends on
      rails (>= 4.2)

    sql-logging was resolved to 3.0.10, which depends on
      rails (>= 4.0)

我实际上不确定这里存在什么问题。这些对rails gem的依赖性似乎并不矛盾,因此我将通过逐一注释掉它们,然后再次尝试更新来尝试找出实际的问题是什么gem。这可能会为您提供更多信息。

Bundler could not find compatible versions for gem "rake":
  In Gemfile:
    rake (~> 11.2)

    capistrano (~> 3.6) was resolved to 3.11.0, which depends on
      rake (>= 10.0.0)

    derailed_benchmarks was resolved to 1.3.2, which depends on
      rake (< 13, > 10)

这似乎也不应该是问题。我会尝试将您的Gemfile中的rake依赖项从gem 'rake', '~> 11.2'更改为gem 'rake',并查看依赖项消息会发生什么。

可能是在完成所有这些步骤之后,您会收到不同错误消息。您必须以相同的方式一一解决。不幸的是,没有灵丹妙药,并且更新Rails可能是一个乏味的过程,尤其是当您的应用程序依赖于许多宝石时。您必须逐个问题地解决此问题,方法是删除自己对gem的依赖关系,帮助gem社区进行维护/更新,或者(最坏的情况)分叉gem并自行更改代码以使其再次适用于您的应用程序。祝你好运!

答案 1 :(得分:0)

为了更新依赖关系,可以使用bummr之类的工具。请确保具有自述文件中指定的良好测试套件。之后,您可以开始解决兼容性问题,弃用等问题。