using Microsoft.EntityFrameworkCore; using WikiWaka.Api.Models; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); builder.Services.AddHealthChecks(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddDbContext(options => options.UseSqlite(builder.Configuration.GetConnectionString("DbWikiWaka"))); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.MapControllers(); app.MapHealthChecks("/healthz"); using (var scope = app.Services.CreateScope()) { await using DbWikiWakaContext db = scope.ServiceProvider.GetRequiredService(); ILogger logger = scope.ServiceProvider.GetRequiredService>(); bool isNewDatabase = await db.Database.EnsureCreatedAsync(); if (isNewDatabase) { logger.LogInformation("Creating new database..."); await DbInit.InitializeLanguages(db); } else logger.LogInformation("Database existed before, not changing"); } app.Run();