Skip to content

Instantly share code, notes, and snippets.

@boie0025
Created December 7, 2012 18:26
Show Gist options
  • Save boie0025/4235272 to your computer and use it in GitHub Desktop.
Save boie0025/4235272 to your computer and use it in GitHub Desktop.
Rake task for gem paper_trail to clean up unused versions.
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