active_version 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -0
- data/lib/active_version/audits/audit_record.rb +6 -1
- data/lib/active_version/audits/has_audits/change_filters.rb +8 -4
- data/lib/active_version/configuration.rb +2 -0
- data/lib/active_version/version.rb +1 -1
- data/lib/generators/active_version/install/templates/initializer.rb.erb +4 -0
- data/sig/active_version/configuration.rbs +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc38a55e873e8ea603bef6bb4bb15350b03582214fc1a48856a05cb35498b845
|
|
4
|
+
data.tar.gz: 34f0c43fb603e0109729c2254ae6d7ee1f95f14f56f3a0b408ffdb1429efdb48
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e13a251346e48e51c617961f433f7384f4cb1dce283f41b1cda977180feb1a116a83a83bf39e241bf15d5f7f67daa926dacb19774ee6c496981e9fbc6c49efb7
|
|
7
|
+
data.tar.gz: 0cd3cfe32df95ac78d6591f5127f1a44c340cb69238b77471029fb5827c4d3c946a44c62b7734fe065bbe75db208162b206919254e4ad33addf5f4a3dab39b2c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.2.0 (2026-03-27)
|
|
4
|
+
|
|
5
|
+
- Fixed SQL generation for audit creation to avoid duplicate `created_at` and `updated_at` columns (or other possible duplicate columns)
|
|
6
|
+
|
|
7
|
+
## 1.1.0 (2026-03-27)
|
|
8
|
+
|
|
9
|
+
- Added `audit_auditable_optional` configuration option to control polymorphic `belongs_to :auditable` optionality
|
|
10
|
+
|
|
3
11
|
## 1.0.1 (2026-03-11)
|
|
4
12
|
|
|
5
13
|
- Fixed Rails 7.2 thread-local audited options handling in `with_audited_options`
|
data/README.md
CHANGED
|
@@ -182,6 +182,8 @@ end
|
|
|
182
182
|
|
|
183
183
|
### Destination Audit Model Configuration (Preferred)
|
|
184
184
|
|
|
185
|
+
The gem defines `belongs_to :auditable` (or your configured column) once, with `optional: false` by default (see `config.audit_auditable_optional`). Set `config.audit_auditable_optional = true` if `auditable_id` is composite or synthetic so polymorphic `load` may not resolve even when columns are valid. Do not re-declare `belongs_to :auditable` in subclasses to tweak options, that can leave duplicate validators from Rails. For presence checks without relying on association load, validate `auditable_type` and `auditable_id` explicitly.
|
|
186
|
+
|
|
185
187
|
```ruby
|
|
186
188
|
class PostAudit < ApplicationRecord
|
|
187
189
|
include ActiveVersion::Audits::AuditRecord
|
|
@@ -135,7 +135,12 @@ module ActiveVersion
|
|
|
135
135
|
# Set up polymorphic association only when conventional id/type columns exist.
|
|
136
136
|
auditable_column = ActiveVersion.column_mapper.column_for(source_class, :audits, :auditable)
|
|
137
137
|
if column_names.include?("#{auditable_column}_id") && column_names.include?("#{auditable_column}_type")
|
|
138
|
-
send(
|
|
138
|
+
send(
|
|
139
|
+
:belongs_to,
|
|
140
|
+
auditable_column,
|
|
141
|
+
polymorphic: true,
|
|
142
|
+
optional: ActiveVersion.config.audit_auditable_optional
|
|
143
|
+
)
|
|
139
144
|
end
|
|
140
145
|
|
|
141
146
|
# Set up user association (if configured)
|
|
@@ -104,11 +104,15 @@ module ActiveVersion
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def prepare_sql_values(changes)
|
|
107
|
-
changes.each_with_object({}) do |(k, v),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
h = changes.each_with_object({}) do |(k, v), acc|
|
|
108
|
+
acc[k] = v.last if v.is_a?(Array)
|
|
109
|
+
acc[k] = v unless v.is_a?(Array)
|
|
110
|
+
acc[k] = JSON.generate(acc[k]) if acc[k].is_a?(Hash) || acc[k].is_a?(Array)
|
|
111
111
|
end
|
|
112
|
+
# Arel INSERT uses keys as column names; stringify so :action / mirror :attrs match
|
|
113
|
+
# string keys from column_mapper and so symbol + string for the same column cannot
|
|
114
|
+
# both appear (PG::DuplicateColumn).
|
|
115
|
+
h.transform_keys(&:to_s)
|
|
112
116
|
end
|
|
113
117
|
end
|
|
114
118
|
end
|
|
@@ -26,6 +26,7 @@ module ActiveVersion
|
|
|
26
26
|
attr_accessor :audit_version_column
|
|
27
27
|
attr_accessor :audit_user_column
|
|
28
28
|
attr_accessor :audit_auditable_column
|
|
29
|
+
attr_accessor :audit_auditable_optional
|
|
29
30
|
attr_accessor :audit_associated_column
|
|
30
31
|
attr_accessor :audit_remote_address_column
|
|
31
32
|
attr_accessor :audit_request_uuid_column
|
|
@@ -64,6 +65,7 @@ module ActiveVersion
|
|
|
64
65
|
@audit_version_column = :version
|
|
65
66
|
@audit_user_column = :user_id
|
|
66
67
|
@audit_auditable_column = :auditable
|
|
68
|
+
@audit_auditable_optional = false
|
|
67
69
|
@audit_associated_column = :associated
|
|
68
70
|
@audit_remote_address_column = :remote_address
|
|
69
71
|
@audit_request_uuid_column = :request_uuid
|
|
@@ -31,6 +31,10 @@ ActiveVersion.configure do |config|
|
|
|
31
31
|
config.audit_remote_address_column = :remote_address
|
|
32
32
|
config.audit_request_uuid_column = :request_uuid
|
|
33
33
|
|
|
34
|
+
# Polymorphic belongs_to :auditable uses optional: false by default. Set true if
|
|
35
|
+
# auditable_id is composite / synthetic and Rails' must-exist validation is wrong for your app.
|
|
36
|
+
# config.audit_auditable_optional = true
|
|
37
|
+
|
|
34
38
|
# Infrastructure note:
|
|
35
39
|
# Connection routing / connection topology / partition lifecycle are application-owned.
|
|
36
40
|
# ActiveVersion reads/writes using the active ActiveRecord connection.
|
|
@@ -21,6 +21,7 @@ module ActiveVersion
|
|
|
21
21
|
attr_accessor audit_version_column: Symbol | String
|
|
22
22
|
attr_accessor audit_user_column: Symbol | String
|
|
23
23
|
attr_accessor audit_auditable_column: Symbol | String
|
|
24
|
+
attr_accessor audit_auditable_optional: bool
|
|
24
25
|
attr_accessor audit_associated_column: Symbol | String
|
|
25
26
|
attr_accessor audit_remote_address_column: Symbol | String
|
|
26
27
|
attr_accessor audit_request_uuid_column: Symbol | String
|