Skip to content

dotnet run -- projections -r deleted streams and events #3826

@kopfrechner

Description

@kopfrechner

Hi,

i just observed some unintended behaviour with the Marten.CommandLine Tool.

It was included as suggested:
https://martendb.io/configuration/cli.html#snippet-sample_using_WebApplication_1

Just short hint, since i think the Extension Methods got updated, they are called now:

...
// Add command line parsing for Marten
builder.Host.ApplyOaktonExtensions();
...
await app.RunOaktonCommands(args);

The observed behaviour is that when i run dotnet run -- projections -r, it deletes all data from the Database.
Not sure if i did something wrong in my setup. It already worked at some point for me.
I also want to mention, it is uncritical to me, since i'm working on a Hobby-Project, but maybe to others.

Here is the state before
Image

Here is the state after running the command
Image

It also occured, when i ran dotnet run -- projections -p <projection-name>.

Marten Setup is this:

Program.cs

var martenConfiguration = builder
    .Services.AddMarten(options => options.SetupStoreOptions(connectionString, isDevelopment))
    .AddSubscriptionWithServices<OnRideFinishedSendEmailNotificationHandler>(
        ServiceLifetime.Singleton,
        o => o.IncludeType<RideFinished>()
    )
    // Another performance optimization if you're starting from scratch
    .UseLightweightSessions()
    // Enable projection daemon
    .AddAsyncDaemon(DaemonMode.Solo);

StoreOptionsExtensions.cs

public static class StoreOptionsExtensions
{
    public static void SetupStoreOptions(
        this StoreOptions options,
        string connectionString,
        bool isDevelopment
    )
    {
        options.Connection(connectionString);

        options.UseSystemTextJsonForSerialization(
            EnumStorage.AsString,
            Casing.Default,
            jsonOptions => jsonOptions.Converters.Add(new JsonStringEnumConverter())
        );

        // If we're running in development mode, let Marten just take care
        // of all necessary schema building and patching behind the scenes
        if (isDevelopment)
        {
            options.AutoCreateSchemaObjects = AutoCreate.All;
        }

        // Ride
        options.Projections.Snapshot<Ride>(SnapshotLifecycle.Inline);
        options.Projections.Add<RideSummaryProjection>(ProjectionLifecycle.Async);

        // Rider
        options.Projections.Snapshot<Rider>(SnapshotLifecycle.Inline);
        options.Projections.Add<RiderHistoryProjection>(ProjectionLifecycle.Inline);
        options.Projections.Add<RiderTripProjection>(ProjectionLifecycle.Async);

        // Recent optimization you'd want with FetchForWriting up above
        options.Projections.UseIdentityMapForAggregates = true;

        // Turn on the PostgreSQL table partitioning for hot/cold storage on archived events
        options.Events.UseArchivedStreamPartitioning = true;
    }
}

Can you see something obvious? Would appreciate some hints.

Best Regards,
Christoph

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions