diff --git a/backend/Program.cs b/backend/Program.cs index e904d68..8d293f0 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -33,6 +33,23 @@ var app = builder.Build(); +using (var scope = app.Services.CreateScope()) +{ + var services = scope.ServiceProvider; + var logger = services.GetRequiredService>(); + try + { + var context = services.GetRequiredService(); + 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();