Skip to content

Fix ProjectionVersion suffix being overwritten by explicit DocumentAlias#4299

Merged
jeremydmiller merged 2 commits intoJasperFx:masterfrom
marcpiechura:fix/projection-version-suffix-with-explicit-alias
Apr 28, 2026
Merged

Fix ProjectionVersion suffix being overwritten by explicit DocumentAlias#4299
jeremydmiller merged 2 commits intoJasperFx:masterfrom
marcpiechura:fix/projection-version-suffix-with-explicit-alias

Conversation

@marcpiechura
Copy link
Copy Markdown
Contributor

When a projection sets ProjectionVersion > 1, the document alias should be suffixed with "_N" so the new version is rebuilt into a parallel mt_doc_xxx_N table (per the documented blue/green deployment pattern). However, when the user supplies an explicit alias via Schema.For().DocumentAlias("...") or [DocumentAlias("...")], that alias was applied AFTER the policy ran, silently overwriting the version suffix. The new shard would then attempt to rebuild into the v1 table and crash on existing v1 documents that lack newly-added fields.

Split the alias-suffix step out of ProjectionDocumentPolicy into a new ProjectionVersionAliasPolicy registered as a post-policy. Post-policies run from StorageFeatures.MappingFor AFTER the fluent builder alterations, so the suffix lands on whatever alias the user actually configured. The remaining Marten-managed defaults (UseOptimisticConcurrency=false, UseNumericRevisions=true, ConfigureAggregateMapping) stay in the pre-policy and continue to win against earlier user-supplied policies.

marcpiechura and others added 2 commits April 28, 2026 11:15
When a projection sets ProjectionVersion > 1, the document alias should
be suffixed with "_N" so the new version is rebuilt into a parallel
mt_doc_xxx_N table (per the documented blue/green deployment pattern).
However, when the user supplies an explicit alias via
Schema.For<T>().DocumentAlias("...") or [DocumentAlias("...")],
that alias was applied AFTER the policy ran, silently overwriting
the version suffix. The new shard would then attempt to rebuild into
the v1 table and crash on existing v1 documents that lack newly-added
fields.

Split the alias-suffix step out of ProjectionDocumentPolicy into a new
ProjectionVersionAliasPolicy registered as a post-policy. Post-policies
run from StorageFeatures.MappingFor AFTER the fluent builder alterations,
so the suffix lands on whatever alias the user actually configured. The
remaining Marten-managed defaults (UseOptimisticConcurrency=false,
UseNumericRevisions=true, ConfigureAggregateMapping) stay in the
pre-policy and continue to win against earlier user-supplied policies.
@jeremydmiller jeremydmiller merged commit 340ea9b into JasperFx:master Apr 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants