update program

This commit is contained in:
2026-03-19 02:04:15 +00:00
parent 7735e3404c
commit 9626d32353

View File

@@ -51,22 +51,30 @@ var app = builder.Build();
using (var scope = app.Services.CreateScope()) using (var scope = app.Services.CreateScope())
{ {
var services = scope.ServiceProvider;
var db = services.GetRequiredService<ApplicationDbContext>();
try try
{ {
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
if (db.Database.GetPendingMigrations().Any()) if (db.Database.GetPendingMigrations().Any())
{ {
db.Database.Migrate(); db.Database.Migrate();
} }
DbInitializer.Initialize(db);
Console.WriteLine("--> Database Seeded Successfully!");
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Database Migration skipped or failed: {ex.Message}"); Console.WriteLine($"Migration notice: {ex.Message}");
}
try
{
Console.WriteLine("--> Checking if Seeding is needed...");
DbInitializer.Initialize(db);
Console.WriteLine("--> Database Seed Completed!");
}
catch (Exception ex)
{
Console.WriteLine($"Seeding failed: {ex.Message}");
} }
} }