Skip to content

Commit 82cb0f7

Browse files
committed
changed using for migrations.
1 parent 645c800 commit 82cb0f7

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

DisBot.API/Startup/Startup.Database.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ private static async Task InitialiseDatabase(this WebApplicationBuilder builder)
1313
private static async Task LoadDatabase(this WebApplication application)
1414
{
1515
application.Logger.Log(LogLevel.Information, "Loading database...");
16-
17-
await using var scope = application.Services.CreateAsyncScope();
18-
var dataContext = scope.ServiceProvider.GetService<DataContext>();
19-
var migrations = await dataContext.Database.GetPendingMigrationsAsync();
20-
if (dataContext == null) throw new Exception("No Database Context found...");
21-
application.Logger.Log(LogLevel.Information, "Database initialized.");
22-
if (migrations.ToArray().Length > 0)
16+
17+
await using (var scope = application.Services.CreateAsyncScope())
2318
{
24-
await dataContext.Database.MigrateAsync();
25-
application.Logger.Log(LogLevel.Information, "Database migrated.");
19+
var dataContext = scope.ServiceProvider.GetService<DataContext>();
20+
var migrations = await dataContext.Database.GetPendingMigrationsAsync();
21+
if (dataContext == null) throw new Exception("No Database Context found...");
22+
application.Logger.Log(LogLevel.Information, "Database initialized.");
23+
if (migrations.ToArray().Length > 0)
24+
{
25+
await dataContext.Database.MigrateAsync();
26+
application.Logger.Log(LogLevel.Information, "Database migrated.");
27+
}
28+
29+
application.Logger.Log(LogLevel.Information, "Database ready to accept connections.");
2630
}
27-
application.Logger.Log(LogLevel.Information, "Database ready to accept connections.");
2831
}
2932
}

0 commit comments

Comments
 (0)