feat: Log EF Core migration errors instead of crashing the application at startup across all services.

This commit is contained in:
Ho Ngoc Hai
2026-02-28 01:03:43 +07:00
parent be86e48de6
commit 751f90c365
19 changed files with 228 additions and 57 deletions

View File

@@ -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();