-
-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mechanism to Import Events #1435
Comments
@Leh2 If it's okay, I'm going to rename this to "Mechanism to Import Events". Like some kind of bulk writer for events? You can always go to the SQL level of course. |
+1 to this idea. We have a few years of data we're migrating from SQL Server to Marten / Postgres and it would be great to have the ability to create the full stream of events from scratch via Marten's API. But, as you mention, we could just go the SQL level too. The latter would probably require extra debugging time though :) |
This is dependent on #780. |
This would be great. I am thinking of migrating from EF core /MS SQL Server to marten and some guidance or some helper api to create events with a specific timestamp (in the past) would be nice. |
Im currently experimenting with the following approach: @oskardudycz @jeremydmiller do you think this is an ok approach for importing existing events from some other data source to marten or do you see obvious problems with this approach? public class MigrationEventListener: IDocumentSessionListener
{
public Task BeforeSaveChangesAsync(IDocumentSession session, CancellationToken token)
{
var streams = session.PendingChanges.Streams();
foreach (var stream in streams)
{
foreach (var e in stream.Events)
{
if (e.Headers.TryGetValue("MigrationTimestamp", out object timestamp))
{
if (timestamp is DateTimeOffset ts)
{
e.Timestamp = ts;
}
}
}
}
return Task.CompletedTask;
}
}
// usage
var x = session.Events.StartStream(id, new SomeEvent { Id = id });
// set header value to some datetimeoffset in the past, depending on our data
var someExistingTimestampFromThePast = DateTimeOffset.UtcNow.AddDays(-150);
x.Events.First().SetHeader("MigrationTimestamp", someExistingTimestampFromThePast ); |
This looks like exactly what I need for my project to be able to use Marten. Take one data format in, transform it somehow, then load it into Marten. |
When migrating old data into the event store it would be beneficial to be able to control the timestamp on events.
This would enable us to use the functionality with aggregate stream and timestamp:
AggregateStreamAsync<T>(Guid streamId, ... DateTime? timestamp = null)
The text was updated successfully, but these errors were encountered: