From 436f3b79dbc98f89b2d561abe1183038b3d8129c Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Mon, 23 Dec 2024 10:24:31 -0600 Subject: [PATCH] Updated weasel, extra tests for migrations with partitioning. Closes GH-3584. Closes GH-3603 Upgraded Weasel Intermediate fixes with Weasel --- ...03_migration_of_soft_deleted_partitions.cs | 34 ++++++++++ .../partitioning_and_foreign_keys.cs | 66 +++++++++++++++++++ .../Marten.CommandLine.csproj | 2 +- .../CompiledQueries/CompiledQueryPlan.cs | 10 +++ src/Marten/Marten.csproj | 2 +- src/Marten/Storage/MartenDatabase.cs | 2 +- src/samples/MinimalAPI/Program.cs | 4 ++ 7 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 src/CoreTests/Bugs/Bug_3603_migration_of_soft_deleted_partitions.cs create mode 100644 src/CoreTests/Partitioning/partitioning_and_foreign_keys.cs diff --git a/src/CoreTests/Bugs/Bug_3603_migration_of_soft_deleted_partitions.cs b/src/CoreTests/Bugs/Bug_3603_migration_of_soft_deleted_partitions.cs new file mode 100644 index 0000000000..7fa0579309 --- /dev/null +++ b/src/CoreTests/Bugs/Bug_3603_migration_of_soft_deleted_partitions.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Xunit; + +namespace CoreTests.Bugs; + +public class Bug_3603_migration_of_soft_deleted_partitions : BugIntegrationContext +{ + [Fact] + public async Task do_not_repeatedly_patch() + { + // Weasel has been erroneously "finding" deltas when it should not + + StoreOptions(opts => + { + opts.Schema.For().SoftDeletedWithPartitioningAndIndex(); + + opts.Events.UseArchivedStreamPartitioning = true; + }); + + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + + await theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync(); + + var store2 = SeparateStore(opts => + { + opts.Schema.For().SoftDeletedWithPartitioningAndIndex(); + opts.Events.UseArchivedStreamPartitioning = true; + }); + + await store2.Storage.Database.AssertDatabaseMatchesConfigurationAsync(); + } +} diff --git a/src/CoreTests/Partitioning/partitioning_and_foreign_keys.cs b/src/CoreTests/Partitioning/partitioning_and_foreign_keys.cs new file mode 100644 index 0000000000..f7056ee030 --- /dev/null +++ b/src/CoreTests/Partitioning/partitioning_and_foreign_keys.cs @@ -0,0 +1,66 @@ +using System.Threading.Tasks; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; +using Weasel.Postgresql.Tables; +using Xunit; + +namespace CoreTests.Partitioning; + +public class partitioning_and_foreign_keys : OneOffConfigurationsContext +{ + /* + * Partitioned to partitioned + * Not partitioned to partitioned + * + * + * + */ + + [Fact] + public async Task from_partitioned_to_not_partitioned() + { + StoreOptions(opts => + { + opts.Schema.For() + .SoftDeletedWithPartitioningAndIndex() + .ForeignKey(x => x.AssigneeId); + }); + + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + await theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync(); + } + + [Fact] + public async Task from_partitioned_to_partitioned() + { + StoreOptions(opts => + { + opts.Schema.For() + .SoftDeletedWithPartitioningAndIndex() + .ForeignKey(x => x.AssigneeId); + + opts.Schema.For().SoftDeletedWithPartitioningAndIndex(); + }); + + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + await theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync(); + } + + [Fact] + public async Task from_not_partitioned_to_partitioned() + { + StoreOptions(opts => + { + opts.Schema.For() + .ForeignKey(x => x.AssigneeId); + + opts.Schema.For().SoftDeletedWithPartitioningAndIndex(); + }); + + await Should.ThrowAsync(async () => + { + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + }); + } +} diff --git a/src/Marten.CommandLine/Marten.CommandLine.csproj b/src/Marten.CommandLine/Marten.CommandLine.csproj index dff27d2958..def02289c6 100644 --- a/src/Marten.CommandLine/Marten.CommandLine.csproj +++ b/src/Marten.CommandLine/Marten.CommandLine.csproj @@ -36,7 +36,7 @@ - + diff --git a/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs b/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs index af81360580..433adc5040 100644 --- a/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs +++ b/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs @@ -103,6 +103,11 @@ private IEnumerable findMembers() #endregion + public void AddParameters(IDictionary parameters) + { + throw new NotImplementedException(); + } + public string TenantId { get; set; } #region ICommandBuilder implementation @@ -250,6 +255,11 @@ void ICommandBuilder.AddParameters(object parameters) "No, just no. Marten does not support parameters via anonymous objects in compiled queries"); } + public void AddParameters(IDictionary parameters) + { + throw new NotImplementedException(); + } + #endregion public QueryStatistics GetStatisticsIfAny(object query) diff --git a/src/Marten/Marten.csproj b/src/Marten/Marten.csproj index c2527b8766..c73309a7a5 100644 --- a/src/Marten/Marten.csproj +++ b/src/Marten/Marten.csproj @@ -61,7 +61,7 @@ - + diff --git a/src/Marten/Storage/MartenDatabase.cs b/src/Marten/Storage/MartenDatabase.cs index d55951bf2b..5a4e9ccec3 100644 --- a/src/Marten/Storage/MartenDatabase.cs +++ b/src/Marten/Storage/MartenDatabase.cs @@ -109,7 +109,7 @@ private void resetSequences() { var sequences = new SequenceFactory(Options, this); - generateOrUpdateFeature(typeof(SequenceFactory), sequences, default).AsTask().GetAwaiter().GetResult(); + generateOrUpdateFeature(typeof(SequenceFactory), sequences, default, true).AsTask().GetAwaiter().GetResult(); return sequences; }); diff --git a/src/samples/MinimalAPI/Program.cs b/src/samples/MinimalAPI/Program.cs index 23c5126168..fa19cf1eb6 100644 --- a/src/samples/MinimalAPI/Program.cs +++ b/src/samples/MinimalAPI/Program.cs @@ -29,6 +29,10 @@ opts.RegisterDocumentType(); opts.DatabaseSchemaName = "cli"; + opts.Events.UseArchivedStreamPartitioning = true; + + opts.Schema.For().SoftDeletedWithPartitioningAndIndex(); + // Register all event store projections ahead of time opts.Projections.Add(new TripProjectionWithCustomName(), ProjectionLifecycle.Async); opts.Projections.Add(new DayProjection(), ProjectionLifecycle.Async);