Skip to content

Range-partition a document table by a non-tenant date column (#4779) - #4780

Merged
jeremydmiller merged 1 commit into
masterfrom
feat/4779-partition-document-by-date
Jun 24, 2026
Merged

jeremydmiller merged 1 commit into
masterfrom
feat/4779-partition-document-by-date

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Closes #4779.

Summary

The public API the issue asks for already exists: DocumentMappingExpression<T>.PartitionOn(member, cfg) range-partitions a document table on a duplicated, caller-chosen member (not just tenant_id). What was missing was a working date-keyed path — the classic time-series retention pattern — because the underlying Weasel partition-bound comparison drifted for timestamptz/quoted literals and reported a spurious, destructive partition rebuild on every migration.

That root cause was fixed in Weasel (JasperFx/weasel#318, shipped in 9.3.0): partition bounds are now compared by normalized instant rather than raw SQL literal, so date (and integer) ranges stay stable across deployments and time zones.

Changes

  • Consume Weasel.Postgresql 9.3.0 (Directory.Packages.props).
  • Regression test src/CoreTests/Partitioning/Bug_4779_partition_document_by_date.cs:
    • marten_managed_monthly_range_partitioning_is_idempotent — a MetricsSample table range-partitioned monthly on a duplicated DateTimeOffset, asserting a re-applied managed range diffs as SchemaPatchDifference.None (the case that depended on the Weasel fix) and that data survives.
    • externally_managed_range_partitioning_by_date — the ByExternallyManagedRangePartitions() (pg_partman / scheduler) variant the issue calls "the most useful first cut".
  • Docs: a "Time-based Retention with Date Range Partitioning" section in docs/documents/storage.md (with snippets), plus partman added to the cSpell dictionary.

Verification

Against the published Weasel 9.3.0: Bug_4779 (2/2) green, and the full CoreTests partitioning sweep (35/35) green. The managed-idempotency test was confirmed to fail against pre-fix Weasel.

Notes

  • No new Marten API surface — this is the dependency bump + tests + docs that make the existing PartitionOn usable for non-tenant date partitioning.
  • ListPartition has the same latent integer-quote drift in Weasel; left for a separate follow-up (range was the reported need).
  • Polecat (SQL Server) parity is a separate follow-up per the issue.

…lumn

The public entry point for this already existed — DocumentMappingExpression<T>.PartitionOn
range-partitions a document table on a duplicated, caller-chosen member — but the
date-keyed time-series retention scenario was unusable because Weasel reported a spurious
destructive partition rebuild on every migration for timestamptz/quoted bounds.

- Consume Weasel.Postgresql 9.3.0 (weasel#318), which compares partition bounds by
  normalized instant instead of raw SQL literal, so date/integer ranges no longer drift.
- Add Bug_4779 regression coverage: a MetricsSample table range-partitioned monthly on a
  duplicated DateTimeOffset, asserting a re-applied managed range diffs as None (the case
  that depended on the Weasel fix) plus the externally-managed (pg_partman) variant.
- Document the time-based retention pattern in storage.md.

Closes #4779
@jeremydmiller
jeremydmiller merged commit 69850df into master Jun 24, 2026
9 checks passed
@jeremydmiller
jeremydmiller deleted the feat/4779-partition-document-by-date branch June 24, 2026 19:20
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.

Range-partition a document table by a non-tenant column (declarative, by date)

1 participant