serverlesstechnology / cqrs

A lightweight, opinionated CQRS and event sourcing framework.
Other
370 stars 40 forks source link

Modifications of Views #82

Closed paulkre closed 11 months ago

paulkre commented 11 months ago

How can I modify View structs reliably? If I have a View for an Aggregate with thousands of instances, and I decide to add an attribute to the view struct, this new attribute will only exist on the instances, that have been updated after the code change. The only way to update all view instances would be to drop the entire view table and replay every event for the view query, right?

paulkre commented 11 months ago

Same goes for aggregate snapshots. If you add an attribute to an aggregate that has been persisted in a snapshot before, it will cause an error when that snapshot is being loaded. We probably need upcasting for snapshots and views too, right?

davegarred commented 11 months ago

You are correct. The usual way to handle that is to truncate your views table and replay all events.

Snapshots will need to be dropped as well. Though you will not need to replay events as the framework will load all events and rebuild the snapshot on the first new command.