paper_trail 12.2.0 → 12.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/paper_trail/install/install_generator.rb +15 -3
- data/lib/generators/paper_trail/install/templates/create_versions.rb.erb +1 -1
- data/lib/paper_trail/events/update.rb +14 -0
- data/lib/paper_trail/record_trail.rb +5 -3
- data/lib/paper_trail/version_number.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0f6ef6591b15081a76d93a70d959527f8cdc53cc3a6343ab6f1b7c40ef6695e
|
4
|
+
data.tar.gz: 202ee3126567ab99b39f8c76039fb7e20a4eb5e10e0e0880e867f19f228ace63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c144126a2d8cec5537ef218b6637ee2ff6e6863de2e935facf6ad020dba6c2fb46bc5c13ed2ab674e9230c264d6e87905415ebc3c1e4bee5fbe50b1e73285663
|
7
|
+
data.tar.gz: 96530aebe8af35a95d47b6a5deadd3797b2d9255b28156f24a9f1be67fe629b254747d39ccad4d8f5d348d9fd74300b4b865ff9b32125c0951b14cf5d13ed60f
|
@@ -20,6 +20,12 @@ module PaperTrail
|
|
20
20
|
default: false,
|
21
21
|
desc: "Store changeset (diff) with each version"
|
22
22
|
)
|
23
|
+
class_option(
|
24
|
+
:uuid,
|
25
|
+
type: :boolean,
|
26
|
+
default: false,
|
27
|
+
desc: "Use uuid instead of bigint for item_id type (use only if tables use UUIDs)"
|
28
|
+
)
|
23
29
|
|
24
30
|
desc "Generates (but does not run) a migration to add a versions table." \
|
25
31
|
" See section 5.c. Generators in README.md for more information."
|
@@ -28,7 +34,8 @@ module PaperTrail
|
|
28
34
|
add_paper_trail_migration(
|
29
35
|
"create_versions",
|
30
36
|
item_type_options: item_type_options,
|
31
|
-
versions_table_options: versions_table_options
|
37
|
+
versions_table_options: versions_table_options,
|
38
|
+
item_id_type_options: item_id_type_options
|
32
39
|
)
|
33
40
|
if options.with_changes?
|
34
41
|
add_paper_trail_migration("add_object_changes_to_versions")
|
@@ -37,13 +44,18 @@ module PaperTrail
|
|
37
44
|
|
38
45
|
private
|
39
46
|
|
47
|
+
# To use uuid instead of integer for primary key
|
48
|
+
def item_id_type_options
|
49
|
+
options.uuid? ? "string" : "bigint"
|
50
|
+
end
|
51
|
+
|
40
52
|
# MySQL 5.6 utf8mb4 limit is 191 chars for keys used in indexes.
|
41
53
|
# See https://github.com/paper-trail-gem/paper_trail/issues/651
|
42
54
|
def item_type_options
|
43
55
|
if mysql?
|
44
|
-
",
|
56
|
+
", null: false, limit: 191"
|
45
57
|
else
|
46
|
-
",
|
58
|
+
", null: false"
|
47
59
|
end
|
48
60
|
end
|
49
61
|
|
@@ -11,7 +11,7 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %>
|
|
11
11
|
def change
|
12
12
|
create_table :versions<%= versions_table_options %> do |t|
|
13
13
|
t.string :item_type<%= item_type_options %>
|
14
|
-
t
|
14
|
+
t.<%= item_id_type_options %> :item_id, null: false
|
15
15
|
t.string :event, null: false
|
16
16
|
t.string :whodunnit
|
17
17
|
t.text :object, limit: TEXT_BYTES
|
@@ -40,6 +40,20 @@ module PaperTrail
|
|
40
40
|
merge_metadata_into(data)
|
41
41
|
end
|
42
42
|
|
43
|
+
# If it is a touch event, and changed are empty, it is assumed to be
|
44
|
+
# implicit `touch` mutation, and will a version is created.
|
45
|
+
#
|
46
|
+
# See https://github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e
|
47
|
+
#
|
48
|
+
# @api private
|
49
|
+
def changed_notably?
|
50
|
+
if @is_touch && changes_in_latest_version.empty?
|
51
|
+
true
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
43
57
|
private
|
44
58
|
|
45
59
|
# @api private
|
@@ -194,15 +194,17 @@ module PaperTrail
|
|
194
194
|
# Save, and create a version record regardless of options such as `:on`,
|
195
195
|
# `:if`, or `:unless`.
|
196
196
|
#
|
197
|
-
#
|
197
|
+
# `in_after_callback`: Indicates if this method is being called within an
|
198
|
+
# `after` callback. Defaults to `false`.
|
199
|
+
# `options`: Optional arguments passed to `save`.
|
198
200
|
#
|
199
201
|
# This is an "update" event. That is, we record the same data we would in
|
200
202
|
# the case of a normal AR `update`.
|
201
|
-
def save_with_version(**options)
|
203
|
+
def save_with_version(in_after_callback: false, **options)
|
202
204
|
::PaperTrail.request(enabled: false) do
|
203
205
|
@record.save(**options)
|
204
206
|
end
|
205
|
-
record_update(force: true, in_after_callback:
|
207
|
+
record_update(force: true, in_after_callback: in_after_callback, is_touch: false)
|
206
208
|
end
|
207
209
|
|
208
210
|
# Like the `update_column` method from `ActiveRecord::Persistence`, but also
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.
|
4
|
+
version: 12.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|