Closed kojuka closed 5 years ago
not really... currently you would need to create a migration script yourself... perhaps by requiring the store implementation (https://github.com/adrai/node-eventstore/blob/master/index.js#L67) and doing something like this: https://github.com/adrai/node-eventstore/blob/master/lib/eventstore.js#L501
you could do it pretty straight forward with a helper script, something like this (semi pseudo code):
// initilize mongo and connect to db;
const col = db.collection('events');
const stream = col.find({}).sort({ commitStamp: 1 });
const batch = [];
for await(const event of stream) {
// manipulate and your event as you wish
// add batch update operation
}
// execute your batch operation
@nanov Ah i see -- That is pretty straight forward. I'll get the events in the store first, then run a simple helper script to override the commitStamp afterwards.
I was hoping to be able to define the commit stamp when adding the events to the event store. This would be a really helpful feature for anyone working on legacy systems or trying to add event sourcing to an existing project. Something like this:
eventStoreClient.getEventStream(streamId, (err, stream) => {
stream.addEvent({
eventType: Events.EVENT_NAME,
data,
commitStamp, // <--- was hoping to be able to pass this in to override the commitStamp
});
stream.commit(async (err, stream) => {
if (err) {
console.log('stream.commit err', err);
}
// do something else
});
});
With a little feedback I'm happy to submit a pull request.
But this other way works too -- thx!
I have a bunch of events I'm copying over from a previous project where I stored events in mysql. I'd like to migrate those events over to this library. Is there a way to create these events while overriding the commitStamp as a previous date?