Skip to content

Commit fac00b4

Browse files
committed
removed Exception from migrations.
1 parent 82cb0f7 commit fac00b4

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

DisBot.API/Startup/Startup.Database.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ private static async Task LoadDatabase(this WebApplication application)
1414
{
1515
application.Logger.Log(LogLevel.Information, "Loading database...");
1616

17-
await using (var scope = application.Services.CreateAsyncScope())
17+
await using var scope = application.Services.CreateAsyncScope();
18+
var dataContext = scope.ServiceProvider.GetService<DataContext>();
19+
var migrations = await dataContext.Database.GetPendingMigrationsAsync();
20+
application.Logger.Log(LogLevel.Information, "Database initialized.");
21+
if (migrations.ToArray().Length > 0)
1822
{
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.");
23+
await dataContext.Database.MigrateAsync();
24+
application.Logger.Log(LogLevel.Information, "Database migrated.");
3025
}
26+
27+
application.Logger.Log(LogLevel.Information, "Database ready to accept connections.");
3128
}
3229
}

0 commit comments

Comments
 (0)