talira

PaperTrail

Track changes to your models, for auditing or versioning

open sourceMITself-hostablefree

PaperTrail records each create, update, destroy and touch of an Active Record model as a row in a versions table, so you can see how a record looked at any point, revert it to an earlier version, or bring it back after it was destroyed. Each version stores the record as it was before the change, optionally the object_changes diff, whodunnit (usually the current user, set by a controller callback) and any metadata you add. You choose which events and attributes to track, can skip sensitive columns, cap versions per record, query versions by their stored values (best with PostgreSQL json or jsonb columns), and plug in your own version classes and serializers. Andy Stewart created it in 2009; association tracking now lives in the separate paper_trail-association_tracking gem.

Problems it solves

  • undo an accidental edit in my Rails app by restoring the record's previous version
  • bring back a record someone deleted, with all its old attribute values
  • see what a model looked like on a specific date
  • record which user made each change to our Rails models for an audit
  • store extra context like the IP address or request ID with each change to a record
  • show a field-by-field list of what changed in each edit
  • track changes to only some columns and never keep sensitive fields in the history
  • our version history table keeps growing; keep only the last few versions per record
  • find every past version of a record where a column had a particular value
  • start versioning models that already have data and still get their original values back
  • keep version history for different models in separate tables
  • turn change tracking off during a bulk import or in tests

Features

  • versions for create, update, destroy and touch
  • reify, revert and undelete records
  • version_at, previous_version and next_version navigation
  • whodunnit from the controller's current_user
  • metadata per version from the model (meta) or the controller (info_for_paper_trail)
  • object_changes for a changeset of each version
  • on, only, ignore, skip, if and unless options
  • version_limit globally or per model
  • where_object and where_object_changes queries; json and jsonb columns on PostgreSQL
  • custom version classes and tables, custom serializers
View 2 more
  • Minitest, RSpec and Cucumber test helpers
  • install generator with an initializer

Limitations

  • Doesn't track or restore associations by itself: that's the separate paper_trail-association_tracking gem1
  • Doesn't diff non-adjacent versions: you write your own code or use a diff library for that1

Capabilities

Has an APIplan not known
Takes pluginsplan not known

Alternatives

The same job

These do what PaperTrail does.

  1. Audited Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.

Compare PaperTrail with the top 3