feat: Log EF Core migration errors instead of crashing the application at startup across all services.
This commit is contained in:
@@ -130,10 +130,19 @@ try
|
||||
// EN: Run the application / VI: Chạy ứng dụng
|
||||
// EN: Auto-apply EF Core migrations on startup
|
||||
// VI: Tự động áp dụng EF Core migrations khi khởi động
|
||||
using (var scope = app.Services.CreateScope())
|
||||
try
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<AdsAnalyticsServiceContext>();
|
||||
await dbContext.Database.MigrateAsync();
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<AdsAnalyticsServiceContext>();
|
||||
await dbContext.Database.MigrateAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// EN: Log migration errors but don't crash the app (e.g. PendingModelChangesWarning in EF Core 10)
|
||||
// VI: Log lỗi migration nhưng không crash app
|
||||
Console.WriteLine($"Warning: EF Core migration issue: {ex.Message}");
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user