If you want to track regressions across your ActiveRecord models, then you can leverage paper_trail
in conjunction with this Rails::Engine
to view and inspect regressions.
Follow instructions to install and setup the paper_trail
gem. Make sure you add the versions
table to your application's database.
Once paper_trail
has been setup, add the has_paper_trail
method to your model.
Then on the following line, add the opsbox_track_regressions
method to the model.
Order is important, since validations are run to ensure has_paper_trail
has been correctly setup.
class User < ApplicationRecord
has_paper_trail
opsbox_track_regressions
end
You are able to specify specific columns you wish to track. This will add a tracked_columns
attribute to your model when you pass in the the only
option as follows:
class User < ApplicationRecord
has_paper_trail
opsbox_track_regressions only: [:name, :address]
end
A notify_changes
method can be added to the model. Here you can define a specific action/alert that needs to happen if any of the model's tracked_columns
change as follows:
class User < ApplicationRecord
has_paper_trail
opsbox_track_regressions only: [:name, :address]
def notify_changes
# Rails.logger.info('Regression detected')
# Sentry.capture_message('Regression detected')
# send an email
# notify another application
end
end
If you wish to utilise the views defined in this engine to inspect changes to your model, then you need to mount the engine in your application's routes.rb file at a desired path.
mount Regressions::Engine => "/regressions"
Add this line to your application's Gemfile:
gem 'regressions'
And then execute:
$ bundle
Or install it yourself as:
$ gem install regressions
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.