Skip to content

Commit

Permalink
db conn check
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Aug 15, 2024
1 parent 9b7f736 commit 86bf23b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@

var app = builder.Build();

using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var logger = services.GetRequiredService<ILogger<Program>>();
try
{
var context = services.GetRequiredService<ApplicationDbContext>();
context.Database.Migrate();
logger.LogInformation("Database connection established and migrated successfully.");
}
catch (Exception ex)
{
logger.LogError(ex, "An error occurred while connecting to the database.");
throw;
}
}

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
Expand Down

0 comments on commit 86bf23b

Please sign in to comment.