0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-06-29 18:21:08 +00:00
CleanArchitecture/CleanArchitecture.Infrastructure/Extensions/DbContextExtension.cs
2023-03-22 19:06:01 +01:00

21 lines
651 B
C#

using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace CleanArchitecture.Infrastructure.Extensions;
public static class DbContextExtension
{
public static void EnsureMigrationsApplied(this DbContext context)
{
var applied = context.GetService<IHistoryRepository>().GetAppliedMigrations().Select(m => m.MigrationId);
var total = context.GetService<IMigrationsAssembly>().Migrations.Select(m => m.Key);
if (total.Except(applied).Any())
{
context.Database.Migrate();
}
}
}