Created
December 7, 2012 18:26
-
-
Save boie0025/4235272 to your computer and use it in GitHub Desktop.
Rake task for gem paper_trail to clean up unused versions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :utils do | |
desc "Clean up papertrail versions: delete unfound associations" | |
task :clean_versions => :environment do | |
Version.all.each do |ver| | |
klass = ver.item_type.constantize | |
#Call unscoped in case delete flag is set, and item is still in db. | |
item = klass.unscoped.find_by_id(ver.item_id) | |
if item.nil? | |
ver.destroy | |
puts "Destroyed: #{ver.inspect}" | |
else | |
puts "Kept: #{ver.inspect}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment