简体   繁体   English

有所有依赖关系的rails版本升级的最佳实践是什么?

[英]What are the best practices for upgrading rails versions with all the dependencies?

whenever some major rails version bump happens, sometimes its real pain to upgrade existing apps for rails (4.x, 5.x etc), given there are plenty of gems which might depend on older versions of rails (ActiveRecord, ActionController, ActiveModel, etc.). 每当发生一些主要的Rails版本冲突时,有时都会升级现有的Rails应用程序(4.x,5.x等),这确实很痛苦,因为有很多宝石可能取决于Rails的较早版本(ActiveRecord,ActionController,ActiveModel,等等。)。 And those dependent gems sometimes takes too much time to be upgrade (either not maintained, less active or unavailability of core maintainer team, even for accepting Pull Requests). 那些依赖的宝石有时需要花费太多时间进行升级(要么不维护,要么不活跃,要么核心维护者团队不可用,即使接受拉取请求也是如此)。 What is the solution which people around follows for the same? 周围的人对于相同的解决方案是什么?

One workflow which people suggest is fork all the dependent gems and then change whatever you like and keep updating them from their respective master/main branches. 人们建议的一种工作流程是派生所有依赖的gem,然后更改您喜欢的任何东西,并继续从其各自的master / main分支进行更新。 I would love to hear what people follow in their workflow. 我很想听听人们在他们的工作流程中遵循的内容。

I would argue that you should remove/replace gems that do not have a compatible version available shortly after a major Rails update. 我认为您应该在主要的Rails更新后不久删除/替换没有兼容版本的gem。

Beta versions of Rails 5 were available almost 6 months before Rails 5 was released. Rails 5的Beta版本在Rails 5发布之前将近6个月可用。 If a gem doesn't update within that time it will probably not be updated later on or it will slow do down on every other Rails update as well. 如果gem在这段时间内没有更新,则以后可能不会更新,或者也会降低其他Rails更新的速度。

I see several options when you run into that situation: 当您遇到这种情况时,我会看到几种选择:

  • Revisit the reason why you are using that gem. 重温使用该宝石的原因。 Sometimes you use a gem for a few simple methods. 有时,您可以通过gem使用一些简单的方法。 Rewrite those methods in your application (or your own gem) and remove this dependency. 在您的应用程序(或您自己的gem)中重写这些方法,并删除此依赖项。

  • Are there other projects available that solve the same problem? 是否有其他解决相同问题的项目? Sometimes these projects even have a better structure or other benefits. 有时,这些项目甚至具有更好的结构或其他好处。 You might consider switching to that gems. 您可能会考虑切换到该宝石。 Hopefully, you encapsulated the old gem and didn't customize that gem too much, because that makes it harder to replace it. 希望您封装了旧的gem,并且没有过多地自定义该gem,因为这使得替换它变得更加困难。

  • You might consider forking that gem and fixing the problem yourself (bonus points for sending a pull request to the original gem). 您可以考虑分叉该宝石并自己解决问题(向原始宝石发送拉取请求的奖励点)。 That is an okay solution in the short-term. 从短期来看,这是一个好的解决方案。 But you will very like have a similar issue with this gem with the next Ruby version. 但是您将非常希望在下一个Ruby版本中与此宝石有类似的问题。 Furthermore, when you work with a forked version of a gem, you are on your own. 此外,当您使用分叉的宝石时,您将自己工作。 Do you really want to maintain that private gem version for the following years? 您是否真的要在接下来的几年中维护该私有gem版本?

With every gem that you add to your stack, there is a cost and a risk coming into your application. 将每一个宝石添加到堆栈中,都​​会给您的应用带来成本和风险。 The cost of watching that gem, how does it change, are there security fixes? 观看该宝石的成本,其变化方式,是否有安全修复程序? And the risk that the gem will be abandoned at some time. 还有宝石将在某个时间被抛弃的风险。

There might be some things you can do upfront to decrease the pain when you run into situations like this: 遇到以下情况时,您可能需要做一些事情来减轻痛苦:

  • Avoid adding gems to your application, when you only need a few simple helper methods from that gem. 当您只需要从gem中使用一些简单的辅助方法时,请避免将gem添加到您的应用程序中。

  • Encapsulate that gem with your own wrapper. 用您自己的包装器封装该宝石。 And have good test coverage for your wrappers interface. 并且对包装器界面具有良好的测试覆盖率。 That makes it much easier to change the underlying gem. 这使得更改基础宝石变得容易得多。

  • Always be prepared to remove/replace gems as soon as you face a problem with them. 遇到宝石问题时,请始终准备好移除/更换宝石。 Waiting for an external gem maintainer is probably not a good strategy when you have problems in your application to solve. 当您的应用程序中有问题要解决时,等待外部的gem维护者可能不是一个好的策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM