auto apply migrations
All checks were successful
Build Docker Images / test (push) Successful in 1m13s
Build Docker Images / build-and-push (push) Successful in 1m28s

This commit is contained in:
Michał Zieliński
2025-11-12 12:16:23 +01:00
parent fd39b72596
commit 5d40af5446

View File

@@ -99,6 +99,33 @@ builder.Services.AddSingleton<PluginManager>();
var app = builder.Build();
// Auto-apply migrations on startup
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
try
{
var pending = await db.Database.GetPendingMigrationsAsync();
if (pending.Any())
{
app.Logger.LogWarning("Applying {Count} pending migrations: {List}",
pending.Count(), string.Join(", ", pending));
await db.Database.MigrateAsync();
app.Logger.LogInformation("Migrations applied successfully.");
}
else
{
app.Logger.LogInformation("No pending migrations.");
}
}
catch (Exception ex)
{
app.Logger.LogCritical(ex, "Migration failed - application will not start.");
throw; // stop startup
}
}
if (app.Environment.IsProduction())
{
app.UseSerilogRequestLogging(options =>