using Microsoft.EntityFrameworkCore; using Server; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); builder.Services.AddDbContextPool(options => { options.UseNpgsql( builder.Configuration.GetConnectionString("SpaceRace"), assembly => assembly.MigrationsAssembly(typeof(SpaceRaceDbContext).Assembly.FullName) ); }); var app = builder.Build(); UpdateDatabase(app); app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); void UpdateDatabase(IApplicationBuilder app) { try { using var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope(); using var context = serviceScope.ServiceProvider.GetService(); context?.Database.Migrate(); } catch (Exception e) { Console.Error.WriteLine("Error migrating db. {0}", e); System.Environment.Exit(1); } }