Saseo - 사서
RabbitMQ based PaperTrail replacement
Overview
Saseo has two primary responsibilities:
- Publishing all changes from a database
- Persisting the changes to a separate data store
Publishing
Saseo uses triggers to temporarily store changes to a local staging table. Saseo provides a stateless executable, saseo_publisher
, that reads the records from that table, publishes them to a RabbitMQ Headers Exchange, then deletes them from the local staging table.
Because the messages are published in this way, the data is available to ANY AND ALL clients that can connect to RabbitMQ.
Published Message Format
Attribute | Details | Header* | Payload** |
---|---|---|---|
table_name | name of the table the record is from | X | |
action | INSERT , UPDATE , or DELETE |
X | |
whodunnit | the user or other entity responsible for the change | X | |
item_id | value, if any, of the id field from the record | X | |
item_uuid | value, if any, of the id field from the record | X | |
transaction_id | transaction_id from the source DB | X | |
locale | I18n.locale of the publisher | X | |
database | source database name for the record | X | |
schema | source schema name for the record | X | |
id | uuid of the saseo version | X | |
old_data | JSON representation of the record before the change | X | |
new_data | JSON representation of the record after the change | X | |
action_timestamp | timestamp from the transaction | X |
* Header: attribute that can be subscribed to
** Payload: attribute that can NOT be subscribed to, only accessible once the message is received
Persistence
Saseo provides a stateless executable, saseo_consumer
, that subscribes to RabbitMQ to pick up the canges published by saseo_publisher
and persists them to a database specified by config. Saseo currently creates one table for every tracked table.
Saseo table structure
Column | Type | Modifiers |
---|---|---|
id | uuid | not null default uuid_generate_v4() |
transaction_id | bigint | not null |
item_id | bigint | |
item_uuid | uuid | |
action | character varying | not null |
action_timestamp | timestamp with time zone | not null |
whodunnit | character varying | not null |
changeset | jsonb | not null |
new_data | jsonb |
Sample Setup
Installation
Add this line to your application's Gemfile:
gem 'saseo'
And then execute:
$ bundle
Or install it yourself as:
$ gem install saseo
Usage
TODO: Write usage instructions here
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/avantcredit/saseo.