Skip to content
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

No longer erroneously creating schema tables for live aggregations re… #3154

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/documents/querying/linq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ implements the traditional [IQueryable](https://msdn.microsoft.com/en-us/library
/// <returns></returns>
IMartenQueryable<T> Query<T>();
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten/IQuerySession.cs#L137-L147' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_querying_with_linq' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten/IQuerySession.cs#L142-L152' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_querying_with_linq' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

To query for all documents of a type - not that you would do this very often outside of testing - use the `Query<T>()` method like this:
Expand Down
2 changes: 1 addition & 1 deletion docs/events/versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Some people prefer to use classes instead of pure functions. It may help encapsu

::: tip
Note the base class used below has 2 generic arguments, the `Upcast()` method only exists
on *this* base class
on _this_ base class
:::

<!-- snippet: sample_upcaster_with_clr_types_and_event_type_name_from_old_type -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using EventSourcingTests.Aggregation;
using Marten.Events.Aggregation;
using Marten.Events.Projections;
using Marten.Schema;
using Marten.Storage;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;

namespace EventSourcingTests.Bugs;

public class Bug_3140_do_not_create_tables_for_live_aggregations : BugIntegrationContext
{
[Fact]
public async Task should_not_create_tables_for_live_aggregations_when_registered_directly()
{
StoreOptions(opts =>
{
opts.Projections.Add(new MyAggregateProjection(), ProjectionLifecycle.Live);
});

await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();

var existingTables = await theStore.Storage.Database.SchemaTables();
existingTables.Any(x => x.QualifiedName == "bugs.mt_doc_aggregate").ShouldBeFalse();

var tables = theStore.Storage.AllObjects().OfType<DocumentTable>();
tables.ShouldNotContain(x => x.DocumentType == typeof(MyAggregate));
}
}

public class MyAggregateProjection: SingleStreamProjection<MyAggregate>
{
public void Apply(MyAggregate aggregate, AEvent e) => aggregate.ACount++;
}
6 changes: 6 additions & 0 deletions src/Marten/Events/Projections/ProjectionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ public void Add<T>(

projection.AssembleAndAssertValidity();

if (lifecycle == ProjectionLifecycle.Live)
{
// Hack to address https://github.com/JasperFx/marten/issues/3140
_options.Storage.MappingFor(typeof(T)).SkipSchemaGeneration = true;
}

All.Add(projection);
}

Expand Down
Loading