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

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<AdsBillingServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AdsBillingServiceContext>();
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();

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<AdsManagerServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AdsManagerServiceContext>();
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();

View File

@@ -135,10 +135,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<AdsServingServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AdsServingServiceContext>();
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();

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<AdsTrackingServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AdsTrackingServiceContext>();
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();

View File

@@ -149,10 +149,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<BookingContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<BookingContext>();
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();

View File

@@ -149,10 +149,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<CatalogContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<CatalogContext>();
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();

View File

@@ -205,10 +205,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<ChatServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ChatServiceContext>();
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();

View File

@@ -149,10 +149,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<FnbContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<FnbContext>();
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();

View File

@@ -152,10 +152,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<InventoryContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<InventoryContext>();
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();

View File

@@ -200,10 +200,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<MembershipServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<MembershipServiceContext>();
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();

View File

@@ -153,10 +153,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<MerchantServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<MerchantServiceContext>();
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();

View File

@@ -220,10 +220,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<MiningServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<MiningServiceContext>();
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();

View File

@@ -150,10 +150,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<MissionDbContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<MissionDbContext>();
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();

View File

@@ -212,10 +212,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<OrderContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<OrderContext>();
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();

View File

@@ -194,10 +194,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<PromotionServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<PromotionServiceContext>();
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();

View File

@@ -156,10 +156,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<SocialServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<SocialServiceContext>();
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();

View File

@@ -185,10 +185,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<StorageServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<StorageServiceContext>();
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();

View File

@@ -179,10 +179,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<WalletServiceContext>();
await dbContext.Database.MigrateAsync();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<WalletServiceContext>();
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();