pyeventsourcing / eventsourcing

A library for event sourcing in Python.
https://eventsourcing.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.45k stars 129 forks source link

[question] rebuild snaphots #39

Closed renou closed 7 years ago

renou commented 7 years ago

Hi John! Is there any ability to discard old snaphots and rebuild new ones? In the case of the change of mutator function, the old snapshot will become invalid and needs to be discarded and rebuilt.

johnbywater commented 7 years ago

It uses the last snapshot when getting an entity, I think. So if you just make another snapshot it should be used. However, when creating the snapshot it might try to use the last one if there haven't been any subsequent events, and anyway it might try to use the old snapshot to get the latest entity state. So you might just need to craft yourself a new function to create new snapshots that doesn't at all use the old snapshots, then the old ones should be ignored. Perhaps that should be an option of the take_snapshot() function.

Please note, if you're using the 'until' option when getting a snapshot, so you see what was effective at a particular time, you will have to decide whether the old projection or the new is required. If you need to see what was effective at a time before the new snapshots are made, but you want the new projection to apply, then you'll have to write some code to update the old snapshot events.

Good luck! Let me know how you get on?

renou commented 7 years ago

yep yep, I agree, maybe a removal of snapshot rows in the database level is enough too in the case of rebuilding snapshots. Let me think more...

johnbywater commented 7 years ago

Yes you could just remove them from the database. In case you were looking, there's zero code in the eventsourcing library to update or delete stored events. Maybe there should be.

renou commented 7 years ago

Yep, my initial idea was to store snapshots in a separate table so that we can clean it up without deleting anything from the event table. Since event table should be append only, I would remove any all user's delete and update privilege of the event table.

johnbywater commented 7 years ago

Good plan 👍 .

renou commented 7 years ago

Oh, btw, we open sourced our django eventsourcing library. It has a django adaptor to this eventsourcing library. Just the schema is a bit different. :)

johnbywater commented 7 years ago

How marvellous. Thanks for lettings me know. I'll check it out!