journaled 6.3.0 → 7.0.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/README.md +24 -0
- data/app/models/concerns/journaled/changes.rb +6 -2
- data/app/models/journaled/change.rb +15 -1
- data/app/models/journaled/change_definition.rb +3 -2
- data/app/models/journaled/change_writer.rb +2 -1
- data/journaled_schemas/journaled/change.json +4 -0
- data/lib/journaled/version.rb +1 -1
- 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: 7da8b60f6a6330d804f54a41a3e0ed2fcd4884e811542599088a9b9d7a9cef29
|
|
4
|
+
data.tar.gz: 489fa98f872666cb5c01a0edc0e4bed2fbc1ed481516cc3abfd363e4f9059f12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2402f321700808215b5b4ecd9c316e575be1edecd043a9ee81b620178548f57ac54e8cf2646de707166162afe7c353f3fde4341222451bcfb7c30b35791b8291
|
|
7
|
+
data.tar.gz: 9c00a20d76b5ac214083d74460a99988513cb33f03d42ad75bf5a7690fc935a6cb04b9413a5d773a96b5f18948e02c988d77b256b5abade72c338b20f4f915cb
|
data/README.md
CHANGED
|
@@ -359,6 +359,17 @@ record is created or destroyed, an event will be sent to Kinesis with the follow
|
|
|
359
359
|
* `actor` - a string (usually a rails global_id) representing who
|
|
360
360
|
performed the action.
|
|
361
361
|
|
|
362
|
+
Pass `tagged: true` to also include a `tags` field sourced from the current
|
|
363
|
+
[tagged event](#tagged-events) context (e.g. `Journaled.tag!`/`Journaled.tagged`):
|
|
364
|
+
|
|
365
|
+
```ruby
|
|
366
|
+
journal_changes_to :email, :first_name, :last_name, as: :identity_change, tagged: true
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
This is useful for capturing metadata (like a session or visitor ID) that isn't
|
|
370
|
+
itself a column on the model. It defaults to `false` to preserve the existing
|
|
371
|
+
event shape for models that don't opt in.
|
|
372
|
+
|
|
362
373
|
Callback-bypassing database methods like `update_all`, `delete_all`,
|
|
363
374
|
`update_columns` and `delete` are intercepted and will require an
|
|
364
375
|
additional `force: true` argument if they would interfere with change
|
|
@@ -847,6 +858,19 @@ gem version.
|
|
|
847
858
|
|
|
848
859
|
As such, **we always recommend upgrading only one major version at a time.**
|
|
849
860
|
|
|
861
|
+
### Upgrading from 6.x
|
|
862
|
+
|
|
863
|
+
`journal_changes_to` now accepts a `tagged:` option (default `false`). This is
|
|
864
|
+
opt-in at the Ruby level, so no application code needs to change to upgrade.
|
|
865
|
+
|
|
866
|
+
However, the `journaled/change` JSON schema (`journaled_schemas/journaled/change.json`)
|
|
867
|
+
now permits an optional `tags` property on every `Journaled::Change` event,
|
|
868
|
+
regardless of whether any particular model opts in. If you (or a downstream
|
|
869
|
+
consumer of this stream) validate `Journaled::Change` payloads against a copy
|
|
870
|
+
of this schema, or against your own stricter schema, that schema needs to
|
|
871
|
+
tolerate a `tags` field being present, since any model in the producing app
|
|
872
|
+
could begin sending it independently of your consumer.
|
|
873
|
+
|
|
850
874
|
### Upgrading from 4.3.0
|
|
851
875
|
|
|
852
876
|
Versions of Journaled prior to 5.0 would enqueue events one at a time, but 5.0
|
|
@@ -56,14 +56,18 @@ module Journaled::Changes
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
class_methods do
|
|
59
|
-
def journal_changes_to(*attribute_names, as:, enqueue_with: {})
|
|
59
|
+
def journal_changes_to(*attribute_names, as:, enqueue_with: {}, tagged: false)
|
|
60
60
|
if attribute_names.empty? || attribute_names.any? { |n| !n.is_a?(Symbol) }
|
|
61
61
|
raise "one or more symbol attribute_name arguments is required"
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
raise "as: must be a symbol" unless as.is_a?(Symbol)
|
|
65
65
|
|
|
66
|
-
_journaled_change_definitions << Journaled::ChangeDefinition.new(
|
|
66
|
+
_journaled_change_definitions << Journaled::ChangeDefinition.new(
|
|
67
|
+
attribute_names: attribute_names,
|
|
68
|
+
logical_operation: as,
|
|
69
|
+
tagged: tagged,
|
|
70
|
+
)
|
|
67
71
|
journaled_attribute_names.concat(attribute_names)
|
|
68
72
|
journaled_enqueue_opts.merge!(enqueue_with)
|
|
69
73
|
end
|
|
@@ -26,7 +26,8 @@ class Journaled::Change
|
|
|
26
26
|
changes:,
|
|
27
27
|
journaled_stream_name:,
|
|
28
28
|
journaled_enqueue_opts:,
|
|
29
|
-
actor
|
|
29
|
+
actor:,
|
|
30
|
+
tagged: false)
|
|
30
31
|
@table_name = table_name
|
|
31
32
|
@record_id = record_id
|
|
32
33
|
@database_operation = database_operation
|
|
@@ -35,5 +36,18 @@ class Journaled::Change
|
|
|
35
36
|
@journaled_stream_name = journaled_stream_name
|
|
36
37
|
@journaled_enqueue_opts = journaled_enqueue_opts
|
|
37
38
|
@actor = actor
|
|
39
|
+
@tagged = tagged
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def tagged?
|
|
43
|
+
@tagged
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def tags
|
|
47
|
+
Journaled::Current.tags
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def journaled_attributes
|
|
51
|
+
tagged? ? super.merge(tags:) : super
|
|
38
52
|
end
|
|
39
53
|
end
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Journaled::ChangeDefinition
|
|
4
|
-
attr_reader :attribute_names, :logical_operation
|
|
4
|
+
attr_reader :attribute_names, :logical_operation, :tagged
|
|
5
5
|
|
|
6
|
-
def initialize(attribute_names:, logical_operation:)
|
|
6
|
+
def initialize(attribute_names:, logical_operation:, tagged: false)
|
|
7
7
|
@attribute_names = attribute_names.map(&:to_s)
|
|
8
8
|
@logical_operation = logical_operation
|
|
9
|
+
@tagged = tagged
|
|
9
10
|
@validated = false
|
|
10
11
|
end
|
|
11
12
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
class Journaled::ChangeWriter
|
|
4
4
|
attr_reader :model, :change_definition
|
|
5
5
|
|
|
6
|
-
delegate :attribute_names, :logical_operation, to: :change_definition
|
|
6
|
+
delegate :attribute_names, :logical_operation, :tagged, to: :change_definition
|
|
7
7
|
|
|
8
8
|
def initialize(model:, change_definition:)
|
|
9
9
|
@model = model
|
|
@@ -33,6 +33,7 @@ class Journaled::ChangeWriter
|
|
|
33
33
|
journaled_stream_name: journaled_stream_name,
|
|
34
34
|
journaled_enqueue_opts: model.journaled_enqueue_opts,
|
|
35
35
|
actor: actor_uri,
|
|
36
|
+
tagged: tagged,
|
|
36
37
|
)
|
|
37
38
|
end
|
|
38
39
|
|
data/lib/journaled/version.rb
CHANGED