Rails 3.2应用程序 - 我应该使用版本控制gem(paper_trail或vestal_versions)还是手动处理它? [英] Rails 3.2 app - Should I use a versioning gem (paper_trail or vestal_versions) or handle it manually?

查看:153
本文介绍了Rails 3.2应用程序 - 我应该使用版本控制gem(paper_trail或vestal_versions)还是手动处理它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:我应该推出自己的模型版本控制还是使用已经存在的版本控制宝石之一?如果我应该使用宝石,哪一个最适合此应用程序?



关于我的应用程序的信息



我的应用程序是一个简单的核对清单应用程序。有检查表和工作,我跟踪回复和提交的用户响应。响应告诉我用法说了什么(完成,注意我们需要更多的拖把),并且提交内容告诉我何时填写了特定的清单(因为可能会有许多提交和给定的响应集清单)。

 #checklist.rb 
类核对清单< ActiveRecord :: Base
has_many:jobs,:through => :checklists_jobs
has_many:意见书
结束

#job.rb
class作业< ActiveRecord :: Base
has_many:checklists,:through => :checklists_jobs
has_many:回应
结束

#response.rb
class回应< ActiveRecord :: Base
belongs_to:job
belongs_to:提交
belongs_to:用户
结束

#submission.rb
class提交< ActiveRecord :: Base
belongs_to:user
belongs_to:清单
has_many:回复
结束

我正在尝试使用版本控制



我想要做的是记录用户的回复到清单上的工作。但是,如果检查清单发生变化,我想确保能够复制原始清单(包含回复信息)。例如,我想确保我可以回答这个问题的所有以前版本的清单:


清单看起来像什么,星期二之前的回应是什么?


如果我更改清单或其任何工作,我不想失去这个问题的答案。



我认为最好的方法是使用版本控制(用于作业和清单)。例如,如果管理员更改了作业(名称或描述),则我不更新现有作业,但创建新版本并保留旧版本。然后,我将原来的东西留在原地,并将清单指向新版本的作业。



我应该使用宝石还是自己滚动?



我想要决定的是我是否应该自己编写代码(编写代码以增加版本,将所有内容指向版本并保留以前的版本)或使用现有的解决方案。两个最好的解决方案似乎是paper_trail和vestal_versions。我没有足够的声望点发布两个以上的链接,所以我会链接到每个gem的Railscast(如果你愿意,它可以让你获得宝石本身)。 Railscast 255使用paper_trail撤消 Railscast 177 Model Versioning - 177使用vestal_versions。



优点滚动我自己:


  • 我需要通过重建清单
    及其响应来报告所有历史数据。这是该应用程序的主要功能。看起来像
    这对我提到的宝石来说会很棘手。

  • 我可以在一组版本中报告
    (我想查看本任务的任何版本
    的所有响应)。这样看起来很简单。



不利于自己滚动:


  • 这会很棘手,因为我有几个has_many:through关联。我必须非常小心地更新所有表并正确连接表。 (这也可能是其中一个宝石的问题)。

  • 由于我使用此版本数据进行报告,因此我担心性能问题。解析哈希看起来在计算上很昂贵,而依赖带索引的平坦表似乎非常高效。 这两个gem似乎更适合于保持版本历史记录以进行跟踪,而不是真正用于维护用于报告目的的历史信息。


这看起来很重要,因为无论我决定什么,我都会坚持下去。我认为稍后从一种方法切换到另一种方法并不容易。

解决方案

我的经验是,当你问关于使用自己的解决方案与使用第三方解决方案的问题,答案几乎总是滚动自己的。您不仅可以根据功能完全做出您想要的内容,还可以让其他开发人员:


  1. 修正错误

  2. 支持最新的rails update / ruby​​更新等。 >
  3. 以某种方式与您的应用程序发生冲突,但无法以您无法解决的微妙方式冲突(需要不同版本的依赖宝石)。

我说如果你有能力,你应该花时间写出你想要的东西。它将在两年后偿还大的时间。

My question: Should I roll my own model versioning or use one of the versioning gems that's already out there? If I should use a gem, which one seems best for this application?

Info about my app

My app is a simple Checklist app. There are Checklists and Jobs, and I track user responses with Responses and Submissions. The Response tells me what the use said ("Done", with a note "We need more mops.") and the Submission tells me when that particular Checklist was filled out (because there may be many submissions and sets of responses for a given checklist). I'll show my associations below, in case that helps.

#checklist.rb
class Checklist < ActiveRecord::Base
  has_many :jobs, :through => :checklists_jobs
  has_many :submissions
end

#job.rb
class Job < ActiveRecord::Base
  has_many :checklists, :through => :checklists_jobs
  has_many :responses
end

#response.rb
class Response < ActiveRecord::Base
  belongs_to :job
  belongs_to :submission
  belongs_to :user
end

#submission.rb
class Submission < ActiveRecord::Base
  belongs_to :user
  belongs_to :checklist
  has_many :responses
end

What I'm trying to do with versioning

What I want to do is record users' responses to jobs on checklists. But I want to make sure that I can reproduce the original checklist (with response information) if the checklist changes. For example, I want to make sure I can answer this question for all previous versions of a checklist:

"What did the checklist look like, and what were the responses three Tuesdays ago?"

I don't want to lose the answer to that question if I change the checklist or any of its jobs.

I think the best way to do this is to use versioning (for jobs and checklists). For example, if a Job is changed (the name or description) by an admin, then I don't update the existing job, but create a new version and leave the old version intact. Then I just leave the old stuff in place and point the checklist to the new version of the job.

Should I use a gem or roll my own?

What I'm trying to decide is whether I should just roll my own (write code to increment the version, point everything to the version, and preserve the previous version) or use an existing solution. The two best solutions seem to be paper_trail and vestal_versions. I don't have enough reputation points to post more than two links, so I'll link to each of gem's Railscast (which will get you to the gem itself if you want). Railscast 255 Undo with paper_trail and Railscast 177 Model Versioning - 177 uses vestal_versions.

Pros to rolling my own:

  • I need to report on all historical data by reconstructing checklists and their responses. This is a main feature of the app. It seems like this will be tricky with the gems I mentioned.
  • I'll be able to report on groups of versions ("I want to see all responses for any version of this Job"). That seems easy this way.

Cons to rolling my own:

  • It's going to be tricky because I have several has_many :through associations. I'll have to be really careful to update all the tables and join tables correctly. (This may also be an issue with one of the gems).
  • Since I'm using this version data for reporting, I'm concerned about performance issues. Parsing hashes seems computationally expensive, whereas relying on flat tables with indexes seems pretty efficient.
  • Both gems seem more geared to keeping version history for tracking, and not really for maintaining historical information for reporting purposes.

This seems important because whatever I decide I'll basically be stuck with. I don't think it will be easy to switch from one method to another later.

解决方案

My experience is that when you ask the question about making your own solution versus using a third-party solution the answer is almost always 'roll your own.' Not only can you make EXACTLY what you want in terms of functionality, you're not beholden to some other developer to:

  1. Fix their bugs
  2. Support the latest rails update/ruby update, etc.
  3. Not conflict in some way with your app in subtle ways you can't address (require different versions of dependent gems).

I say that if you have the ability you should spend the time and write exactly what you want. It will pay off big time two years from now.

这篇关于Rails 3.2应用程序 - 我应该使用版本控制gem(paper_trail或vestal_versions)还是手动处理它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆