Log model changes to Cassandra.
Ruby Shell
Latest commit 0d12a8d Oct 4, 2011 @therealadam Release 0.7.3
Permalink
Failed to load latest commit information.
.bundle Update bundle config after installing with bundler 1.0.13. May 5, 2011
examples
lib Release 0.7.3 Oct 4, 2011
test Upgrade cassandra gem. Aug 10, 2011
.gitignore Upgrade to Cassandra 0.7. Apr 13, 2011
.rvmrc Update Ruby version, autocreate gemset, add CI build script. May 5, 2011
Gemfile Upgrade cassandra gem. Aug 10, 2011
LICENSE
README.md Update readme with a TimeUUID schema. Sep 29, 2010
Rakefile Rename tests to autotest conventions. Nov 18, 2010
audit.gemspec

README.md

Audit

Audit sits on top of your model objects and watches for changes to your data. When a change occurs, the differences are recorded and stored in Cassandra.

Usage

Include Audit::Tracking into your change-sensitive ActiveRecord models. When you make changes to data in those tables, the relevant details will be written to a Cassandra column family.

Example

>> require 'audit'
>> class User < ActiveRecord::Base; include Audit::Tracking; end
>> u = User.create(:name => 'Adam', :city => 'Dallas')
>> u.update_attributes(:city => 'Austin')
>> u.audits
[#<struct Audit::Changeset changes=[#<struct Audit::Change attribute="username", old="akk", new="therealadam">]>, #<struct Audit::Changeset changes=[#<struct Audit::Change attribute="username", old="adam", new="akk">]>, #<struct Audit::Changeset changes=[#<struct Audit::Change attribute="age", old=30, new=31>]>]

Compatibility

Audit is tested against ActiveRecord 3.0, Ruby 1.8.7 and Ruby 1.9.2.

Setup

For Cassandra 0.7, you can set up the schema with cassandra-cli like so:

/* Create a new keyspace */
create keyspace Audit with replication_factor = 1

/* Switch to the new keyspace */
use Audit

/* Create new column families */
create column family Audits with column_type = 'Standard' and comparator = 'TimeUUIDType' and rows_cached = 10000

For Cassandra 0.6, add the following to storage-conf.xml:

<Keyspace Name="Audit">
    <KeysCachedFraction>0.01</KeysCachedFraction>
    <ColumnFamily CompareWith="TimeUUIDType" Name="Audits" />
    <ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
    <ReplicationFactor>1</ReplicationFactor>
    <EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>
</Keyspace>

Hacking

Set up RVM:

$ rvm install ree-1.8.7-2010.01
$ rvm use ree-1.8.7-2010.01
$ rvm gemset create audit
$ rvm gemset use audit
$ gem install bundler
$ bundle install
$ rvm install 1.9.2
$ rvm use 1.9.2
$ rvm gemset create audit
$ rvm gemset use audit
$ gem install bundler
$ bundle install

Run the test suite with all supported runtimes:

$ rvm 1.9.2@audit,ree-1.8.7-2010.01@audit rake test

TODO

  • Ignore changes on some attributes
  • Add more AR callbacks (delete, ?)
  • Generate bucket names for namespaced models

License

Copyright 2010 Adam Keys <adam@therealaadam.com>

Audit is MIT licensed. Enjoy!