RavenDB.Bundles.Revisions

A RavenDB plugin and client that automatically maintains previous versions of a document, if the document has a Revision property of type int. This is an alternative to Raven's 'Versioning' bundle in that:

  • It only works on documents that have a Revision property.
  • It allows Revisions to be deleted.
  • It allows Revisions to be overwritten.
  • Your application controls the Revision number and not the plugin.
  • Your application is resposible for revision number contiguity.

While Raven's 'Versioning' bundle is designed for regulatad environments, such as healtcare, where nothing can be deleted, this bundle is more useful for applications where the document is a result of a projection (i.e. CQRS) and where the 'source of truth' comes from somewhere else and where projections / documents can easily be rebuilt.

Install

Packages are available nuget.org

Using

If you want your this plugin to automatically create revision copies add a Revision property to your document:

public class MyDocument
{
    public string Id { get; set;}
    
    public int Revision { get; set; }
}

When a revisionable document is saved, the plugin will create a copy with a new id. These copies are excluded from all indexes. You should be aware that these revisions are kept indefinitely until you have specifically deleted them or used Raven's 'Expiration' bundle to perform automatic purging.

To retireve a specific revision of a document use the LoadRevision extension method:

using(var session = store.OpenSession)
{
    var doc = session.LoadRevision("key", 2);
}

To delete a specific revision of a document:

_documentStore.DatabaseCommands.DeleteRevision("key", 2, null);