Upgrade
An upgrade of a domain event's stored JSON from revision from to revision from + 1. An event at Revision n needs one upgrade from each of the revisions 1 to n - 1: the model processor chains them, and a gap, a duplicate, an upgrade from 0 or less or from the current revision or beyond, or one of a class that is not an event of an aggregate in the module, is a compile error.
The function takes the payload as a Jackson JsonNode or ObjectNode (tools.jackson.databind) and returns the upgraded one as either; it is pure, does no I/O and does not suspend. Since the generated model calls it with no instance, it is a top-level function, or a member of an object (a companion object included) or a Java static method, in the same module as the aggregate, and not private. A member of the aggregate root or of its state is not accepted: put it in their companion object.
@Revision(2)
data class ItemAdded(val productId: String, val quantity: Int)
@Upgrade(event = ItemAdded::class, from = 1)
fun quantityDefaultsToOne(node: ObjectNode): ObjectNode = node.put("quantity", 1)Parameters
the event class.
the revision this upgrades from, 1 or more and below the event's current revision.