Reputation: 246
The scenario is that I have two ActiveModels: Invitation
and Guest
.
I've published a bunch of events to the event stream of an invitation and at some point that invitation is accepted and subsequently a guest is created. I would like to copy the events on the event stream of the invitation across to the event stream of the guest.
I've thought of duplicating using dup
the original events, updating the stream field to be the guest's event stream but this will violate the unique constraint of the event_id field. So I would like the EventStore's publish
mechanism to handle the persistence of the event.
I've thought of copying the data
attribute of the original events across to new instances of the events and using publish
but then I would get metadata (request_id
, remote_ip
, timestamp
) on the event that does not reflect that of the original events which is important to keep for audibility.
Is there some technique to perform this kind of transfer / duplication of RailsEventStore events?
Upvotes: 0
Views: 217
Reputation: 281
There is a technique — linking. In recent Rails Event Store releases (since v0.22.0) you're able to link an existing event to other streams: https://railseventstore.org/docs/link/. It retains the data and metadata.
Upvotes: 1