Skip to content

Commit

Permalink
Making the managed list partitions better able to do migrations acros…
Browse files Browse the repository at this point in the history
…s process restarts. Bumps to 7.11.3
  • Loading branch information
jeremydmiller committed Oct 7, 2024
1 parent eac0791 commit 8634839
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>7.11.2</Version>
<Version>7.11.3</Version>
<LangVersion>12.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,35 @@ public async Task apply_additive_migration()
partitioning.Partitions.Select(x => x.Suffix).OrderBy(x => x)
.ShouldBe(new []{"blue", "green", "purple", "red"});
}

[Fact]
public async Task apply_additive_migration_2()
{
var database = new ManagedListDatabase();
var partitions = new Dictionary<string, string> { { "red", "red" }, { "green", "green" }, { "blue", "blue" }, };
await database.Partitions.ResetValues(database, partitions, CancellationToken.None);

await database.ApplyAllConfiguredChangesToDatabaseAsync();

// RECREATE a new instance of the database
database = new ManagedListDatabase();

await database.Partitions.AddPartitionToAllTables(database, "purple", "purple", CancellationToken.None);

var tables = await database.FetchExistingTablesAsync();

var teams = tables.Single(x => x.Identifier.Name == "teams");
var partitioning = teams.Partitioning.ShouldBeOfType<ListPartitioning>();
partitioning.HasExistingDefault.ShouldBeFalse();
partitioning.Partitions.Select(x => x.Suffix).OrderBy(x => x)
.ShouldBe(new []{"blue", "green", "purple", "red"});

var players = tables.Single(x => x.Identifier.Name == "players");
partitioning = players.Partitioning.ShouldBeOfType<ListPartitioning>();
partitioning.HasExistingDefault.ShouldBeFalse();
partitioning.Partitions.Select(x => x.Suffix).OrderBy(x => x)
.ShouldBe(new []{"blue", "green", "purple", "red"});
}
}

public class ManagedListDatabase: PostgresqlDatabase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public async Task AddPartitionToAllTables(PostgresqlDatabase database, string va
await using var conn = database.CreateConnection();
await conn.OpenAsync(token).ConfigureAwait(false);

// This is idempotent, so just do it here
await InitializeAsync(conn, token).ConfigureAwait(false);

await AddPartitionToAllTables(conn, token, value, suffix).ConfigureAwait(false);

var tables = database
Expand Down

0 comments on commit 8634839

Please sign in to comment.