Server now silently fails with no PostgreSQL

This commit is contained in:
2026-06-18 18:47:42 -04:00
parent 6a2a8abb22
commit 3904e0bce5
4 changed files with 48 additions and 16 deletions
+18 -3
View File
@@ -10,15 +10,30 @@ builder.Services.AddRazorPages();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(connectionString));
{
if (!string.IsNullOrEmpty(connectionString))
{
options.UseNpgsql(connectionString);
}
});
var app = builder.Build();
// Apply migrations
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
db.Database.Migrate();
try
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
if (!string.IsNullOrEmpty(connectionString))
{
db.Database.Migrate();
}
}
catch (Exception ex)
{
Console.WriteLine($"[WARNING] Database migration failed: {ex.Message}. The application will continue without a database connection.");
}
}
// Configure the HTTP request pipeline.