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

Updated weasel, extra tests for migrations with partitioning. Closes … #3607

Merged
merged 1 commit into from
Dec 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
Original file line number Diff line number Diff line change
@@ -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<Target>().SoftDeletedWithPartitioningAndIndex();

opts.Events.UseArchivedStreamPartitioning = true;
});

await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();

await theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync();

var store2 = SeparateStore(opts =>
{
opts.Schema.For<Target>().SoftDeletedWithPartitioningAndIndex();
opts.Events.UseArchivedStreamPartitioning = true;
});

await store2.Storage.Database.AssertDatabaseMatchesConfigurationAsync();
}
}
66 changes: 66 additions & 0 deletions src/CoreTests/Partitioning/partitioning_and_foreign_keys.cs
Original file line number Diff line number Diff line change
@@ -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<Issue>()
.SoftDeletedWithPartitioningAndIndex()
.ForeignKey<User>(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<Issue>()
.SoftDeletedWithPartitioningAndIndex()
.ForeignKey<User>(x => x.AssigneeId);

opts.Schema.For<User>().SoftDeletedWithPartitioningAndIndex();
});

await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
await theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync();
}

[Fact]
public async Task from_not_partitioned_to_partitioned()
{
StoreOptions(opts =>
{
opts.Schema.For<Issue>()
.ForeignKey<User>(x => x.AssigneeId);

opts.Schema.For<User>().SoftDeletedWithPartitioningAndIndex();
});

await Should.ThrowAsync<InvalidForeignKeyException>(async () =>
{
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
});
}
}
2 changes: 1 addition & 1 deletion src/Marten.CommandLine/Marten.CommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageReference Include="JasperFx.CodeGeneration.Commands" Version="3.7.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Oakton" Version="6.3.0" />
<PackageReference Include="Weasel.CommandLine" Version="7.12.3" />
<PackageReference Include="Weasel.CommandLine" Version="7.13.1" />
</ItemGroup>
<Import Project="../../Analysis.Build.props"/>
</Project>
10 changes: 10 additions & 0 deletions src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ private IEnumerable<MemberInfo> findMembers()

#endregion

public void AddParameters<T>(IDictionary<string, T> parameters)
{
throw new NotImplementedException();
}

public string TenantId { get; set; }

#region ICommandBuilder implementation
Expand Down Expand Up @@ -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<string, object> parameters)
{
throw new NotImplementedException();
}

#endregion

public QueryStatistics GetStatisticsIfAny(object query)
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Marten.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<PackageReference Include="Polly.Core" Version="8.5.0" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Weasel.Postgresql" Version="7.12.3" />
<PackageReference Include="Weasel.Postgresql" Version="7.13.1" />
</ItemGroup>

<!--SourceLink specific settings-->
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Storage/MartenDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
4 changes: 4 additions & 0 deletions src/samples/MinimalAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
opts.RegisterDocumentType<User>();
opts.DatabaseSchemaName = "cli";

opts.Events.UseArchivedStreamPartitioning = true;

opts.Schema.For<Target>().SoftDeletedWithPartitioningAndIndex();

// Register all event store projections ahead of time
opts.Projections.Add(new TripProjectionWithCustomName(), ProjectionLifecycle.Async);
opts.Projections.Add(new DayProjection(), ProjectionLifecycle.Async);
Expand Down
Loading