using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Infrastructure
{
  public static class ApplicationBuilderExtensions
  {
    public static IApplicationBuilder UseHNDatabaseMigrations(this IApplicationBuilder builder)
    {
      using var scope = builder.ApplicationServices.CreateScope();
      using var context = scope.ServiceProvider.GetRequiredService<HNDbContext>();
      context.Database.Migrate();

      return builder;
    }
  }
}