Skip to content

Commit 11d057a

Browse files
committed
fix: tests again
1 parent 186985d commit 11d057a

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎RepositoryServer.Tests/Integration/WebApplicationFactory.cs‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
8+
using Microsoft.Extensions.Logging.Abstractions;
99
using OpenShock.RepositoryServer.RepoServerDb;
1010
using OpenShock.RepositoryServer.Services;
1111
using OpenShock.RepositoryServer.Tests.Integration.Docker;
@@ -34,13 +34,20 @@ public sealed class WebApplicationFactory
3434

3535
public async Task InitializeAsync()
3636
{
37-
_ = Server; // force the host to build
37+
// Schema first, host second. Npgsql reads PostgreSQL's type catalogue once, on the first
38+
// connection a data source opens, and caches it for that data source's lifetime. The enum
39+
// types are created by the migrations, so anything that connects before they have run leaves
40+
// the host's data source permanently unable to bind release_channel, repository_provider and
41+
// friends — the schema is correct and every write of an enum still fails. Building the host
42+
// here rather than below is what put a startup connection ahead of the migrations.
43+
await using (var migrationContext = new MigrationOpenShockContext(
44+
PostgreSql.Container.GetConnectionString(), debug: false,
45+
NullLoggerFactory.Instance))
46+
{
47+
await migrationContext.Database.MigrateAsync();
48+
}
3849

39-
await using var scope = Services.CreateAsyncScope();
40-
var loggerFactory = scope.ServiceProvider.GetRequiredService<ILoggerFactory>();
41-
await using var migrationContext = new MigrationOpenShockContext(
42-
PostgreSql.Container.GetConnectionString(), debug: false, loggerFactory);
43-
await migrationContext.Database.MigrateAsync();
50+
_ = Server; // force the host to build
4451
}
4552

4653
/// <summary>

0 commit comments

Comments
 (0)