module Logidze
Logidze
provides tools for adding in-table JSON-based audit to DB tables and ActiveRecord extensions to work with changes history.
Constants
- VERSION
Attributes
append_on_undo[RW]
Determines if Logidze
should append a version to the log after updating an old version.
associations_versioning[RW]
Determines whether associations versioning is enabled or not
ignore_log_data_by_default[RW]
Determines if Logidze
should exclude log data from SELECT statements
on_pending_upgrade[R]
Determines what Logidze
should do when upgrade is needed (:raise | :warn | :ignore)
return_self_if_log_data_is_empty[RW]
Whether at should return self or nil when log_data is nil
sort_triggers_by_name[RW]
Determines if triggers are sorted by related table id or by name
Public Class Methods
on_pending_upgrade=(mode)
click to toggle source
# File lib/logidze.rb, line 49 def on_pending_upgrade=(mode) if %i[raise warn ignore].exclude? mode raise ArgumentError, "Unknown on_pending_upgrade option `#{mode.inspect}`. Expecting :raise, :warn or :ignore" end @on_pending_upgrade = mode end
with_full_snapshot() { || ... }
click to toggle source
Instruct Logidze
to create a full snapshot for the new versions, not a diff
@example
Logidze.with_full_snapshot { post.touch }
# File lib/logidze.rb, line 45 def with_full_snapshot with_logidze_setting("logidze.full_snapshot", "on") { yield } end
without_logging() { || ... }
click to toggle source
Temporary disable DB triggers.
@example
Logidze.without_logging { Post.update_all(active: true) }
# File lib/logidze.rb, line 37 def without_logging with_logidze_setting("logidze.disabled", "on") { yield } end
Private Class Methods
with_logidze_setting(name, value) { || ... }
click to toggle source
# File lib/logidze.rb, line 58 def with_logidze_setting(name, value) ActiveRecord::Base.transaction do ActiveRecord::Base.connection.execute "SET LOCAL #{name} TO #{value};" res = yield ActiveRecord::Base.connection.execute "SET LOCAL #{name} TO DEFAULT;" res end end