diff --git a/src/CoreTests/Partitioning/partitioning_documents_on_duplicate_fields.cs b/src/CoreTests/Partitioning/partitioning_documents_on_duplicate_fields.cs index 260f7e8da7..fffa923888 100644 --- a/src/CoreTests/Partitioning/partitioning_documents_on_duplicate_fields.cs +++ b/src/CoreTests/Partitioning/partitioning_documents_on_duplicate_fields.cs @@ -38,7 +38,7 @@ public static void configure_partitioning() { opts.Connection("some connection string"); - // Set up table partitioning for the User document type + // Set up table partitioning for the User document type using RANGE partitioning opts.Schema.For() .PartitionOn(x => x.Age, x => { @@ -48,17 +48,6 @@ public static void configure_partitioning() .AddRange("thirties", 31, 39); }); - // Or use pg_partman to manage partitioning outside of Marten - opts.Schema.For() - .PartitionOn(x => x.Age, x => - { - x.ByExternallyManagedRangePartitions(); - - // or instead with list - - x.ByExternallyManagedListPartitions(); - }); - // Or use PostgreSQL HASH partitioning and split the users over multiple tables opts.Schema.For() .PartitionOn(x => x.UserName, x => @@ -66,6 +55,7 @@ public static void configure_partitioning() x.ByHash("one", "two", "three"); }); + // Or use PostgreSQL LIST partitioning and split the users over multiple tables opts.Schema.For() .PartitionOn(x => x.Status, x => { @@ -76,6 +66,21 @@ public static void configure_partitioning() .AddPartition("new", "New"); }); + // Or use pg_partman to manage partitioning outside of Marten + opts.Schema.For() + .PartitionOn(x => x.Age, x => + { + x.ByExternallyManagedRangePartitions(); + + // or instead with list + + x.ByExternallyManagedListPartitions(); + + // or instead with hash + + x.ByExternallyManagedHashPartitions(); + }); + }); #endregion diff --git a/src/Marten/PartitioningExpression.cs b/src/Marten/PartitioningExpression.cs index 72987d6f06..06b172e67f 100644 --- a/src/Marten/PartitioningExpression.cs +++ b/src/Marten/PartitioningExpression.cs @@ -15,6 +15,17 @@ public PartitioningExpression(DocumentMapping mapping, string[] columnNames) _columnNames = columnNames; } + /// + /// Direct Marten to use PostgreSQL HASH-based partitioning, but to allow the partitions to be managed + /// externally from Marten + /// + public void ByExternallyManagedHashPartitions() + { + _mapping.IgnorePartitions = true; + var partitioning = new HashPartitioning { Columns = _columnNames }; + _mapping.Partitioning = partitioning; + } + /// /// Direct Marten to apply equally sized PostgreSQL HASH-based partitioning with a partition for /// each named partition suffix