-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to automatically limit the number of stored versions #213
Comments
+1 It would be nice, if i would not have to run cron or similar. When creating a new version, the older ones can be deleted by this event. |
Agreed this seems like it would be a nice feature, the caveat being that the version referencing a 'create' event (which could be important for some users if they use that feature) would also be automatically deleted, so we may need an option to preserve that one. Perhaps #212 could be merged in a way that would allow it to serve this purpose, as well as the scenario proposed by @seanmarcia in the pull request. I realize these are certainly different scenario's, however, a module named |
By the way if you wanted a simple implementation of this until we have a more permanent solution, you could do something like this: # config/initializers/paper_trail.rb
class Version < ActiveRecord::Base
class << self
attr_accessor :version_limit # maximum number of versions per item
end
after_create do
return unless self.class.version_limit
preceding_siblings = sibling_versions.preceding(self)
preceding_siblings.last.destroy if preceding_siblings.size > self.class.version_limit
end
end You could then change the limit (globally) by using |
I'd definitely like to see more use cases, I'd be happy to modify or provide additional cleaner methods. I realize that mine was a solution specific to a problem we were having. |
Thanks. My only use case is that in the admin part of the app I want to be able to fix any mistake that I make, including mistakes that I might not realise until I've made a few more changes to the instance. Keeping, say, the five most recent versions of an instance gives me plenty of insurance. Keeping, say, no more than the five most recent versions stops my database from swelling uncontrollably. I'll try the temporary solution listed above. |
Just out of curiosity, is there a specific reason this limit ended up being global vs per model? |
No, not really, I think it was just the implementation that was suggested, but could have gone either way. |
OK, just wondering. If I need this feature, I'll just submit a pull Andrew On Wed, Oct 1, 2014 at 11:52 AM, Ben Atkins [email protected]
|
Always open to pull requests. |
+1 for model specific version limits |
Please see #915 if you'd like to help implement this feature or have something constructive to add. |
I know there are tools for manually deleted versions created before a certain date.
I'm looking to configure PaperTrail globally so it only ever stores n many versions of each instance.
something like
config.version_limit = 5
If there are n versions stored, and PaperTrail wants to store a new one, it automatically deletes the oldest to make room.
Is this possible?
The text was updated successfully, but these errors were encountered: