From aaead6f4487d993f6bb2ac5a35be8c51164141f5 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Thu, 26 Sep 2024 16:13:30 -0500 Subject: [PATCH] Upgrading Weasel to fix an issue with managed list partitions when not using the string value as the partition suffix --- src/Marten/Marten.csproj | 2 +- .../marten_managed_tenant_id_partitioning.cs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Marten/Marten.csproj b/src/Marten/Marten.csproj index 0978cd6143..47b3b47107 100644 --- a/src/Marten/Marten.csproj +++ b/src/Marten/Marten.csproj @@ -48,7 +48,7 @@ - + diff --git a/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs b/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs index 8ff852ae2b..0cb040429b 100644 --- a/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs +++ b/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -73,6 +74,43 @@ await theStore } + [Fact] + public async Task can_build_storage_with_dynamic_tenants_by_variable_tenant_and_suffix_mappings() + { + StoreOptions(opts => + { + opts.Policies.AllDocumentsAreMultiTenanted(); + opts.Policies.PartitionMultiTenantedDocumentsUsingMartenManagement("tenants"); + + opts.Schema.For(); + opts.Schema.For(); + }, true); + + var tenantId1 = Guid.NewGuid().ToString(); + var tenantId2 = Guid.NewGuid().ToString(); + var tenantId3 = Guid.NewGuid().ToString(); + + var names = new Dictionary + { + { tenantId1, "a1" }, { tenantId2, "a2" }, { tenantId3, "a3" } + }; + + await theStore + .Advanced + // This is ensuring that there are tenant id partitions for all multi-tenanted documents + // with the named tenant ids + .AddMartenManagedTenantsAsync(CancellationToken.None, names); + + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + + var targetTable = await theStore.Storage.Database.ExistingTableFor(typeof(Target)); + assertTableHasTenantPartitions(targetTable, "a1", "a2", "a3"); + + var userTable = await theStore.Storage.Database.ExistingTableFor(typeof(User)); + assertTableHasTenantPartitions(userTable, "a1", "a2", "a3"); + + } + [Fact] public async Task can_build_then_add_additive_partitions_later() {