|
5 | 5 | using Microsoft.Extensions.Configuration; |
6 | 6 | using Microsoft.Extensions.DependencyInjection; |
7 | 7 | using Microsoft.Extensions.Hosting; |
8 | | -using Microsoft.Extensions.Logging; |
| 8 | +using Microsoft.Extensions.Logging.Abstractions; |
9 | 9 | using OpenShock.RepositoryServer.RepoServerDb; |
10 | 10 | using OpenShock.RepositoryServer.Services; |
11 | 11 | using OpenShock.RepositoryServer.Tests.Integration.Docker; |
@@ -34,13 +34,20 @@ public sealed class WebApplicationFactory |
34 | 34 |
|
35 | 35 | public async Task InitializeAsync() |
36 | 36 | { |
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 | + } |
38 | 49 |
|
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 |
44 | 51 | } |
45 | 52 |
|
46 | 53 | /// <summary> |
|
0 commit comments