A versioning plugin for Elixir.
Entities that are marked as versioned with the acts_as_versioned statement will automatically have a history table created and a timestamp and version column added to their tables. In addition, versioned entities are provided with four new methods: revert, revert_to, compare_with and get_as_of, and one new attribute: versions. Entities with compound primary keys are supported.
The versions attribute will contain a list of previous versions of the instance, in increasing version number order.
The get_as_of method will retrieve a previous version of the instance "as of" a specified datetime. If the current version is the most recent, it will be returned.
The revert method will rollback the current instance to its previous version, if possible. Once reverted, the current instance will be expired from the session, and you will need to fetch it again to retrieve the now reverted instance.
The revert_to method will rollback the current instance to the specified version number, if possibe. Once reverted, the current instance will be expired from the session, and you will need to fetch it again to retrieve the now reverted instance.
The compare_with method will compare the instance with a previous version. A dictionary will be returned with each field difference as an element in the dictionary where the key is the field name and the value is a tuple of the format (current_value, version_value). Version instances also have a compare_with method so that two versions can be compared.
Also included in the module is a after_revert decorator that can be used to decorate methods on the versioned entity that will be called following that instance being reverted.
The acts_as_versioned statement also accepts an optional ignore argument that consists of a list of strings, specifying names of fields. Changes in those fields will not result in a version increment. In addition, you can pass in an optional check_concurrent argument, which will use SQLAlchemy's built-in optimistic concurrency mechanisms.
Note that relationships that are stored in mapping tables will not be included as part of the versioning process, and will need to be handled manually. Only values within the entity's main table will be versioned into the history table.