Skip to content

Commit

Permalink
New IDatabaseInitializer model. Bumps to 7.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Sep 18, 2024
1 parent 49e91d1 commit 48d2383
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
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.10.0</Version>
<Version>7.11.0</Version>
<LangVersion>12.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
12 changes: 7 additions & 5 deletions src/Weasel.Core/Migrations/DatabaseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Weasel.Core.Migrations;
private readonly Func<TConnection> _connectionSource;
private readonly IMigrationLogger _logger;
private readonly TimedLock _migrateLocker = new();
private readonly List<IDatabaseInitializer<TConnection>> _initializers = new();

public DatabaseBase(
IMigrationLogger logger,
Expand All @@ -36,6 +37,11 @@ public DatabaseBase(
Identifier = identifier;
}

public void AddInitializer(IDatabaseInitializer<TConnection> initializer)
{
_initializers.Add(initializer);
}

private static TConnection CreateConnection(string connectionString)
{
var conn = new TConnection();
Expand Down Expand Up @@ -83,11 +89,7 @@ public async Task AssertConnectivityAsync(CancellationToken ct = default)

private async Task initializeSchema(TConnection connection, CancellationToken token)
{
var initializers = BuildFeatureSchemas()
.OfType<IFeatureSchemaWithInitialization<TConnection>>()
.ToArray();

foreach (var initializer in initializers)
foreach (var initializer in _initializers)
{
await initializer.InitializeAsync(connection, token).ConfigureAwait(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Weasel.Core/Migrations/IFeatureSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Weasel.Core.Migrations;

public interface IFeatureSchemaWithInitialization<T> where T : DbConnection
public interface IDatabaseInitializer<T> where T : DbConnection
{
Task InitializeAsync(T connection, CancellationToken token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IListPartitionManager
IEnumerable<ListPartition> Partitions();
}

public class ManagedListPartitions : FeatureSchemaBase, IFeatureSchemaWithInitialization<NpgsqlConnection>, IListPartitionManager
public class ManagedListPartitions : FeatureSchemaBase, IDatabaseInitializer<NpgsqlConnection>, IListPartitionManager
{
private readonly Table _table;
private Dictionary<string, string> _partitions = new();
Expand Down

0 comments on commit 48d2383

Please sign in to comment.