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
Original file line number Diff line number Diff line change
Expand Up @@ -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<User>()
.PartitionOn(x => x.Age, x =>
{
Expand All @@ -48,24 +48,14 @@ public static void configure_partitioning()
.AddRange("thirties", 31, 39);
});

// Or use pg_partman to manage partitioning outside of Marten
opts.Schema.For<User>()
.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<User>()
.PartitionOn(x => x.UserName, x =>
{
x.ByHash("one", "two", "three");
});

// Or use PostgreSQL LIST partitioning and split the users over multiple tables
opts.Schema.For<Issue>()
.PartitionOn(x => x.Status, x =>
{
Expand All @@ -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<User>()
.PartitionOn(x => x.Age, x =>
{
x.ByExternallyManagedRangePartitions();

// or instead with list

x.ByExternallyManagedListPartitions();

// or instead with hash

x.ByExternallyManagedHashPartitions();
});

});

#endregion
Expand Down
11 changes: 11 additions & 0 deletions src/Marten/PartitioningExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ public PartitioningExpression(DocumentMapping mapping, string[] columnNames)
_columnNames = columnNames;
}

/// <summary>
/// Direct Marten to use PostgreSQL HASH-based partitioning, but to allow the partitions to be managed
/// externally from Marten
/// </summary>
public void ByExternallyManagedHashPartitions()
{
_mapping.IgnorePartitions = true;
var partitioning = new HashPartitioning { Columns = _columnNames };
_mapping.Partitioning = partitioning;
}

/// <summary>
/// Direct Marten to apply equally sized PostgreSQL HASH-based partitioning with a partition for
/// each named partition suffix
Expand Down
Loading