using Microsoft.EntityFrameworkCore; namespace Cloud.Middlewares; public static class DatabaseMiddleware { public static void AddDbConnectionService(this IServiceCollection services) { string connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING") ?? "Host=localhost;Port=5438;Database=main_database;Username=postgres;Password=12345"; services.AddDbContext(options => options.UseNpgsql(connectionString)); } public static void MigrateDb(this IApplicationBuilder app) { try { using var scope = app.ApplicationServices.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); context.Database.Migrate(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }