diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 6a793ef..6b2a01c 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "csharpier": { - "version": "0.16.0", + "version": "0.27.3", "commands": [ "dotnet-csharpier" ] @@ -15,7 +15,7 @@ ] }, "dotnet-ef": { - "version": "6.0.0", + "version": "8.0.0", "commands": [ "dotnet-ef" ] diff --git a/.idea/.idea.IntegreSql.EF/.idea/indexLayout.xml b/.idea/.idea.IntegreSql.EF/.idea/indexLayout.xml index 7b08163..bbdf908 100644 --- a/.idea/.idea.IntegreSql.EF/.idea/indexLayout.xml +++ b/.idea/.idea.IntegreSql.EF/.idea/indexLayout.xml @@ -1,7 +1,11 @@ - + + .config + .github + scripts + diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml index 266213b..bf14980 100644 --- a/scripts/docker-compose.yml +++ b/scripts/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.4" services: integresql: - image: allaboutapps/integresql:1.0.0 + image: ghcr.io/allaboutapps/integresql:v1.1.0 restart: always depends_on: - postgres_internal diff --git a/src/MccSoft.IntegreSql.EF/NpgsqlDatabaseInitializer.cs b/src/MccSoft.IntegreSql.EF/NpgsqlDatabaseInitializer.cs index a1318f8..5e84216 100644 --- a/src/MccSoft.IntegreSql.EF/NpgsqlDatabaseInitializer.cs +++ b/src/MccSoft.IntegreSql.EF/NpgsqlDatabaseInitializer.cs @@ -143,11 +143,35 @@ await _integreSqlClient GetDatabaseDto newDatabase = await _integreSqlClient .GetTestDatabase(databaseHash) .ConfigureAwait(false); - return GetConnectionString( + var connectionString = GetConnectionString( newDatabase.Database.Config, newDatabase.Database.TemplateHash, newDatabase.Id ); + + // Due to https://github.com/allaboutapps/integresql/issues/17 + // IntegreSQL returns connection string before database is actually available. + // So we have to wait. + await WaitUntilDatabaseIsCreated(connectionString); + + return connectionString; + } + + private async Task WaitUntilDatabaseIsCreated(string connectionString) + { + for (int i = 0; i < 100; i++) + { + try + { + await using var conn = new NpgsqlConnection(connectionString); + await conn.OpenAsync(); + return; + } + catch (PostgresException e) when (e.SqlState == "3D000") + { + await Task.Delay(TimeSpan.FromMilliseconds(100)); + } + } } ///