Skip to content

Commit

Permalink
add WaitUntilDatabaseIsCreated to support Integresql v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddix committed Mar 5, 2024
1 parent 5cb5185 commit b81f7cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.16.0",
"version": "0.27.3",
"commands": [
"dotnet-csharpier"
]
Expand All @@ -15,7 +15,7 @@
]
},
"dotnet-ef": {
"version": "6.0.0",
"version": "8.0.0",
"commands": [
"dotnet-ef"
]
Expand Down
6 changes: 5 additions & 1 deletion .idea/.idea.IntegreSql.EF/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion src/MccSoft.IntegreSql.EF/NpgsqlDatabaseInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

/// <summary>
Expand Down

0 comments on commit b81f7cf

Please sign in to comment.