Setup
Add “trackzored” to your model. By convention, any attribute that also has [ATTR]_updated_at or [ATTR]_updated_by will be maintained. You can optionally specify :only and :except if this convention steps on your toes – :except => :status would skip the check and update of status_updated_at and status_updated_by. If [ATTR]_updated_by is present, it is required by a validator. If acts_as_audited is present, trackzor-maintained columns will be added to non_audited_columns to prevent double-auditing.
Use the trackzor_migration generator to quickly add columns:
script/generate trackzor_migration User email phone_number
This will create a migration for adding email_updated_at, email_updated_by, phone_number_updated_at, and phone_number_updated_by columns.
Usage
To set the current user:
Trackzor.as_user(user_obj) do
...
end
Or, if you’re also using acts_as_audited, its as_user method is supported:
Audit.as_user(user_obj) do
...
end
For each trackzored [ATTR]_updated_by column, a belongs_to association (:[ATTR]_source) is added to link to the user.
Sharing and Merging Tables
Trackzor provides rake tasks for consolidating development databases. When using Trackzor as a gem, copy trackzor.rake from the gem’s tasks directory to your application’s tasks directory.
Merging from Person A to Person B:
Person A: > rake trackzor_merge:dump TABLE=users
/path/printed/to/dump/users_for_merge.sql
Person B: > rake trackzor_merge:load CLASS=User FILE=users_for_merge.sql COLUMN=email
Merging [email protected] {:zip_code => ['12345', '54321']}
Creating [email protected]
...
Trackzor will load the DB dump into a temporary table and merge data that is newer (based on ATTR_updated_at if available, otherwise updated_at).