using Elsa.Common.Multitenancy;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.EntityFrameworkCore;
///
/// Executes EF Core migrations using the specified type.
///
[UsedImplicitly]
public class RunMigrationsHostedService(IServiceScopeFactory scopeFactory) : MultitenantHostedService(scopeFactory) where TDbContext : DbContext
{
///
protected override async Task StartAsync(TenantScope tenantScope, CancellationToken cancellationToken)
{
var dbContextFactory = tenantScope.ServiceProvider.GetRequiredService>();
var tenantDbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
await tenantDbContext.Database.MigrateAsync(cancellationToken);
}
}