Skip to content
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 Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net9.0;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>4.0.0-alpha.10</Version>
<Version>4.0.0-rc.1</Version>
<LangVersion>latest</LangVersion>
<Authors>Jeremy D. Miller</Authors>
<PackageIcon>logo.png</PackageIcon>
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

<ItemGroup>
<!-- Core dependencies -->
<PackageVersion Include="JasperFx" Version="2.0.0-alpha.20" />
<PackageVersion Include="JasperFx.Events" Version="2.0.0-alpha.20" />
<PackageVersion Include="JasperFx" Version="2.0.0-rc.2" />
<PackageVersion Include="JasperFx.Events" Version="2.0.0-rc.2" />
<!-- Pin the sibling JasperFx packages for parity with Marten 9's matrix
even though Polecat doesn't currently reference them directly —
keeps the lockstep matrix coherent when transitive resolution
surfaces them through JasperFx / JasperFx.Events updates. The
RuntimeCompiler 5.x line is the active continuation of the 4.x
lineage; do not pin against the parallel stale 2.0.x series. -->
<PackageVersion Include="JasperFx.RuntimeCompiler" Version="5.0.0-alpha.8" />
<PackageVersion Include="JasperFx.SourceGeneration" Version="2.0.0-alpha.9" />
<PackageVersion Include="JasperFx.RuntimeCompiler" Version="5.0.0-rc.2" />
<PackageVersion Include="JasperFx.SourceGeneration" Version="2.0.0-rc.2" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
Expand All @@ -33,14 +33,14 @@
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
<PackageVersion Include="Weasel.EntityFrameworkCore" Version="9.0.0-alpha.7" />
<PackageVersion Include="Weasel.SqlServer" Version="9.0.0-alpha.7" />
<PackageVersion Include="Weasel.EntityFrameworkCore" Version="9.0.0-alpha.8" />
<PackageVersion Include="Weasel.SqlServer" Version="9.0.0-alpha.8" />

<!-- Strongly typed IDs -->
<PackageVersion Include="StronglyTypedId" Version="1.0.0-beta08" />

<!-- Source generators -->
<PackageVersion Include="JasperFx.Events.SourceGenerator" Version="2.0.0-alpha.12" />
<PackageVersion Include="JasperFx.Events.SourceGenerator" Version="2.0.0-rc.2" />

<!-- Build automation -->
<PackageVersion Include="Nuke.Common" Version="9.0.4" />
Expand Down
39 changes: 38 additions & 1 deletion docs/documents/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,51 @@ Explicitly set the expected revision:
session.UpdateRevision(order, expectedRevision: 3);
```

## Long Numeric Revisions (ILongVersioned)

`ILongVersioned` is the 64-bit counterpart of `IRevisioned` — identical behavior, but the revision is
a `long` instead of an `int`:

```cs
public class CustomerOrderHistory : ILongVersioned
{
public Guid Id { get; set; }
public long Version { get; set; }
public string Description { get; set; } = "";
}
```

Usage mirrors `IRevisioned`, with a `long` overload of `UpdateRevision` for explicit checks:

```cs
var view = await session.LoadAsync<CustomerOrderHistory>(id);
view.Description = "Updated";
session.UpdateRevision(view, expectedRevision: 4_000_000_000L);
await session.SaveChangesAsync();
```

::: tip
Prefer `ILongVersioned` over `IRevisioned` for `MultiStreamProjection`-derived views whose `Version`
tracks the **global event sequence number**. That sequence is monotonic across every stream the view
folds in and can climb past `Int32.MaxValue` (~2.1 billion) on a busy store, where an `int` revision
would overflow. A plain single-stream aggregate, whose `Version` is just that stream's event count,
is fine with `IRevisioned`.
:::

Both interfaces persist into the same `version` column, which is always `bigint` (Decision D2) so the
two are storage-compatible: `IRevisioned` values fit and are downcast on read, while `ILongVersioned`
carries the full 64-bit value. Existing tables with an `int` version column are widened to `bigint`
in place on the next schema migration — a non-destructive `ALTER COLUMN`, never a drop/recreate.

## Configuration

### Auto-Detection

Polecat automatically detects concurrency mode from interfaces:

- Implements `IVersioned` → Guid-based versioning
- Implements `IRevisioned` → Numeric revisions
- Implements `IRevisioned` → Numeric revisions (int)
- Implements `ILongVersioned` → Numeric revisions (long)

### Manual Configuration

Expand Down
2 changes: 1 addition & 1 deletion docs/documents/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Depending on configuration, additional columns may be present:
| `is_deleted` | `bit` | Soft deletes enabled |
| `deleted_at` | `datetimeoffset` | Soft deletes enabled |
| `guid_version` | `uniqueidentifier` | `IVersioned` interface |
| `version` | `int` | `IRevisioned` interface |
| `version` | `bigint` | Revision counter (`IRevisioned` int / `ILongVersioned` long) |
| `correlation_id` | `nvarchar(250)` | Metadata tracking |
| `causation_id` | `nvarchar(250)` | Metadata tracking |

Expand Down
7 changes: 5 additions & 2 deletions docs/schema/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ deleted_at datetimeoffset NULL
guid_version uniqueidentifier NULL
```

### Numeric Revisions (IRevisioned)
### Numeric Revisions (IRevisioned / ILongVersioned)

The `version` column is always `bigint` (Decision D2), carrying both `IRevisioned` (int, downcast on
read) and `ILongVersioned` (long) revisions. Every write sets it explicitly, so it has no default.

```sql
version int NOT NULL DEFAULT 0
version bigint NOT NULL
```

### Conjoined Tenancy
Expand Down
4 changes: 4 additions & 0 deletions src/Polecat.EntityFrameworkCore.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Critter Stack 2026 dedupe pillar (jasperfx#214): TenancyStyle lifted to
// JasperFx.MultiTenancy (#127 / jasperfx#327). Mirror the alias used by the
// Polecat.EntityFrameworkCore assembly so this test code keeps compiling.
global using TenancyStyle = JasperFx.MultiTenancy.TenancyStyle;
5 changes: 5 additions & 0 deletions src/Polecat.EntityFrameworkCore/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Critter Stack 2026 dedupe pillar (jasperfx#214): TenancyStyle was lifted to
// JasperFx.MultiTenancy (#127 / jasperfx#327). This extension assembly references it
// unqualified in the EF Core projection storage wiring; alias it like the core
// Polecat assembly does in its own GlobalUsings.cs.
global using TenancyStyle = JasperFx.MultiTenancy.TenancyStyle;
2 changes: 1 addition & 1 deletion src/Polecat.Tests/BulkInsert/bulk_insert_operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task bulk_insert_syncs_itenanted_metadata()
// ITenanted.TenantId should have been set to the default tenant
foreach (var doc in docs)
{
doc.TenantId.ShouldBe(Tenancy.DefaultTenantId);
doc.TenantId.ShouldBe(JasperFx.StorageConstants.DefaultTenantId);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Polecat.Tests/Documents/DocumentMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private class DateTimeIdDoc

private class NonStandardWithProp
{
[Polecat.Attributes.Identity]
[JasperFx.Identity]
public string Name { get; set; } = string.Empty;

public string Other { get; set; } = string.Empty;
Expand All @@ -211,19 +211,19 @@ private class IdAndIdentityAttDoc
{
public Guid Id { get; set; }

[Polecat.Attributes.Identity]
[JasperFx.Identity]
public string DocumentId { get; set; } = string.Empty;
}

private class GuidIdentityDoc
{
[Polecat.Attributes.Identity]
[JasperFx.Identity]
public Guid UniqueId { get; set; }
}

private class IntIdentityDoc
{
[Polecat.Attributes.Identity]
[JasperFx.Identity]
public int Number { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Polecat.Tests/Documents/DocumentStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void session_has_default_tenant_id()
{
using var store = DocumentStore.For(ConnectionSource.ConnectionString);
var session = store.LightweightSession();
session.TenantId.ShouldBe(Tenancy.DefaultTenantId);
session.TenantId.ShouldBe(JasperFx.StorageConstants.DefaultTenantId);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Polecat.Tests/Events/fetch_stream_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task fetch_stream_events_have_tenant_id()
await using var query = theStore.QuerySession();
var events = await query.Events.FetchStreamAsync(streamId);

events[0].TenantId.ShouldBe(Tenancy.DefaultTenantId);
events[0].TenantId.ShouldBe(JasperFx.StorageConstants.DefaultTenantId);
}

[Fact]
Expand Down
13 changes: 13 additions & 0 deletions src/Polecat.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Critter Stack 2026 dedupe pillar (jasperfx#214): mirror src/Polecat/GlobalUsings.cs
// so test code keeps referencing the lifted types by their old unqualified names.
// These were lifted out of Polecat into JasperFx / JasperFx.Events (#127/#128/#135);
// the aliases below cover every name the test assembly still uses unqualified.
global using TenancyStyle = JasperFx.MultiTenancy.TenancyStyle;
global using DeleteStyle = JasperFx.DeleteStyle;
global using DcbConcurrencyException = JasperFx.Events.DcbConcurrencyException;
global using ProgressionProgressOutOfOrderException = JasperFx.Events.Daemon.ProgressionProgressOutOfOrderException;
global using ISoftDeleted = JasperFx.Metadata.ISoftDeleted;
global using IVersioned = JasperFx.Metadata.IVersioned;
global using ITracked = JasperFx.Metadata.ITracked;
global using RemoveAction = JasperFx.Events.RemoveAction;
global using TrackLevel = JasperFx.OpenTelemetry.TrackLevel;
12 changes: 12 additions & 0 deletions src/Polecat.Tests/Harness/TestDocumentTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public class RevisionedDoc : IRevisioned
public int Version { get; set; }
}

/// <summary>
/// Document with long-based revision tracking via ILongVersioned. Recommended for
/// MultiStreamProjection-derived views where Version is the global event sequence number,
/// which can exceed Int32.MaxValue.
/// </summary>
public class LongVersionedDoc : ILongVersioned
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public long Version { get; set; }
}

/// <summary>
/// Document with Guid-based optimistic concurrency via IVersioned.
/// </summary>
Expand Down
16 changes: 10 additions & 6 deletions src/Polecat.Tests/Metadata/tracked_operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ public class TrackedDoc : ITracked
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? CorrelationId { get; set; }
public string? CausationId { get; set; }
public string? LastModifiedBy { get; set; }
// Non-nullable to match the lifted JasperFx.Metadata.ITracked (jasperfx#330);
// SyncMetadata always copies non-null session values onto these.
public string CorrelationId { get; set; } = string.Empty;
public string CausationId { get; set; } = string.Empty;
public string LastModifiedBy { get; set; } = string.Empty;
}

public class TenantedDoc : ITenanted
Expand All @@ -164,8 +166,10 @@ public class FullMetadataDoc : ITracked, ITenanted
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? CorrelationId { get; set; }
public string? CausationId { get; set; }
public string? LastModifiedBy { get; set; }
// Non-nullable to match the lifted JasperFx.Metadata.ITracked (jasperfx#330);
// SyncMetadata always copies non-null session values onto these.
public string CorrelationId { get; set; } = string.Empty;
public string CausationId { get; set; } = string.Empty;
public string LastModifiedBy { get; set; } = string.Empty;
public string TenantId { get; set; } = string.Empty;
}
61 changes: 61 additions & 0 deletions src/Polecat.Tests/Schema/document_schema_resolver_tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using JasperFx.Events;
using Polecat;
using Shouldly;

namespace Polecat.Tests.Schema;

/// <summary>
/// Coverage for Polecat's implementation of the lifted
/// <see cref="IDocumentSchemaResolver"/> (jasperfx#333), exposed as
/// <c>StoreOptions.SchemaResolver</c>.
/// </summary>
public class document_schema_resolver_tests
{
private sealed record Customer(Guid Id, string Name);

private static IDocumentSchemaResolver ResolverFor(string schema)
{
var options = new StoreOptions { DatabaseSchemaName = schema };
return options.SchemaResolver;
}

[Fact]
public void resolves_schema_names()
{
var resolver = ResolverFor("events");
resolver.DatabaseSchemaName.ShouldBe("events");
// Events share the document schema in Polecat.
resolver.EventsSchemaName.ShouldBe("events");
}

[Fact]
public void resolves_event_store_tables_qualified_and_bare()
{
var resolver = ResolverFor("dbo");

resolver.ForEvents().ShouldBe("[dbo].[pc_events]");
resolver.ForStreams().ShouldBe("[dbo].[pc_streams]");
resolver.ForEventProgression().ShouldBe("[dbo].[pc_event_progression]");

resolver.ForEvents(qualified: false).ShouldBe("pc_events");
resolver.ForStreams(qualified: false).ShouldBe("pc_streams");
resolver.ForEventProgression(qualified: false).ShouldBe("pc_event_progression");
}

[Fact]
public void resolves_document_table_by_type()
{
var resolver = ResolverFor("app");

resolver.For<Customer>().ShouldBe("[app].[pc_doc_customer]");
resolver.For<Customer>(qualified: false).ShouldBe("pc_doc_customer");
resolver.For(typeof(Customer)).ShouldBe("[app].[pc_doc_customer]");
resolver.For(typeof(Customer), qualified: false).ShouldBe("pc_doc_customer");
}

[Fact]
public void honors_custom_schema()
{
ResolverFor("tenant_a").ForEvents().ShouldBe("[tenant_a].[pc_events]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json.Serialization;
using Polecat.Serialization;
using Polecat.Tests.Harness;
using Weasel.Core;

namespace Polecat.Tests.Serialization;

Expand Down
2 changes: 1 addition & 1 deletion src/Polecat.Tests/SessionOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void default_tracking_is_none()
public void default_tenant_id()
{
var options = new SessionOptions();
options.TenantId.ShouldBe(Tenancy.DefaultTenantId);
options.TenantId.ShouldBe(JasperFx.StorageConstants.DefaultTenantId);
}

[Fact]
Expand Down
Loading
Loading