diff --git a/src/EventSourcingTests/Projections/using_explicit_code_for_live_aggregation.cs b/src/EventSourcingTests/Projections/using_explicit_code_for_live_aggregation.cs index 6cf2140834..4f5b28a01d 100644 --- a/src/EventSourcingTests/Projections/using_explicit_code_for_live_aggregation.cs +++ b/src/EventSourcingTests/Projections/using_explicit_code_for_live_aggregation.cs @@ -1,17 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; using EventSourcingTests.Aggregation; using EventSourcingTests.FetchForWriting; -using Marten; using Marten.Events; using Marten.Events.Aggregation; using Marten.Events.Projections; -using Marten.Internal.Sessions; using Marten.Testing.Harness; using Shouldly; +using Weasel.Postgresql.Tables; using Xunit; namespace EventSourcingTests.Projections; @@ -37,6 +35,7 @@ public async Task using_a_custom_projection_for_live_aggregation() aggregate.Id.ShouldBe(streamId); } + [Fact] public async Task using_a_custom_projection_for_live_aggregation_with_query_session() { @@ -48,7 +47,7 @@ public async Task using_a_custom_projection_for_live_aggregation_with_query_sess var streamId = theSession.Events.StartStream(new AEvent(), new AEvent(), new BEvent(), new CEvent(), new CEvent(), new CEvent()).Id; await theSession.SaveChangesAsync(); - using var query = theStore.QuerySession(); + await using var query = theStore.QuerySession(); var aggregate = await query.Events.AggregateStreamAsync(streamId); aggregate.ACount.ShouldBe(2); @@ -56,6 +55,23 @@ public async Task using_a_custom_projection_for_live_aggregation_with_query_sess aggregate.CCount.ShouldBe(3); aggregate.Id.ShouldBe(streamId); } + + [Fact] + public async Task does_not_create_tables() + { + StoreOptions(opts => + { + opts.Projections.Add(new ExplicitCounter(), ProjectionLifecycle.Live); + }); + + var streamId = theSession.Events.StartStream(new AEvent(), new AEvent(), new BEvent(), new CEvent(), new CEvent(), new CEvent()).Id; + await theSession.SaveChangesAsync(); + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + + var eventStream = await theSession.Events.FetchForWriting(streamId); + var tables = theStore.Storage.AllObjects().OfType(); + tables.ShouldNotContain(x => x.Identifier.Name.Contains(nameof(SimpleAggregate), StringComparison.OrdinalIgnoreCase)); + } } #region sample_using_simple_explicit_code_for_live_aggregation diff --git a/src/Marten.Testing/hiearchy_projection.cs b/src/Marten.Testing/hiearchy_projection.cs index c50492fe0a..0b707c6c2b 100644 --- a/src/Marten.Testing/hiearchy_projection.cs +++ b/src/Marten.Testing/hiearchy_projection.cs @@ -34,8 +34,6 @@ public async Task try_to_use_hierarchical_with_live() opts.Logger(new TestOutputMartenLogger(_output)); }); - await store.Advanced.Clean.DeleteDocumentsByTypeAsync(typeof(Thing)); - using var session = store.LightweightSession(); var id1 = session.Events.StartStream(new ThingStarted("small"), new ThingFed()).Id; var id2 = session.Events.StartStream(new ThingStarted("big"), new ThingFed()).Id; diff --git a/src/Marten/Events/Projections/ProjectionOptions.cs b/src/Marten/Events/Projections/ProjectionOptions.cs index bbf90db740..65151cbb22 100644 --- a/src/Marten/Events/Projections/ProjectionOptions.cs +++ b/src/Marten/Events/Projections/ProjectionOptions.cs @@ -165,6 +165,11 @@ public void Add( throw new ArgumentOutOfRangeException(nameof(lifecycle), $"{nameof(ProjectionLifecycle.Live)} cannot be used for IProjection"); } + + if (projection is IAggregateProjection aggregateProjection) + { + _options.Storage.MappingFor(aggregateProjection.AggregateType).SkipSchemaGeneration = true; + } } if (projection is ProjectionBase p)