< Summary

Information
Class: Elsa.Persistence.EFCore.RunMigrationsStartupTask<T>
Assembly: Elsa.Persistence.EFCore.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/RunMigrationsStartupTask.cs
Line coverage
85%
Covered lines: 6
Uncovered lines: 1
Coverable lines: 7
Total lines: 29
Line coverage: 85.7%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()50%2283.33%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/RunMigrationsStartupTask.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Common.RecurringTasks;
 3using JetBrains.Annotations;
 4using Microsoft.EntityFrameworkCore;
 5using Microsoft.Extensions.Options;
 6
 7// ReSharper disable once CheckNamespace
 8namespace Elsa.Persistence.EFCore;
 9
 10/// <summary>
 11/// Executes EF Core migrations using the specified <see cref="DbContext"/> type.
 12/// </summary>
 13[UsedImplicitly]
 14[SingleNodeTask]
 15[Order(-100)]
 616public class RunMigrationsStartupTask<TDbContext>(IDbContextFactory<TDbContext> dbContextFactory, IOptions<MigrationOpti
 17{
 18    /// <inheritdoc />
 19    public async Task ExecuteAsync(CancellationToken cancellationToken)
 20    {
 621        options.Value.RunMigrations.TryGetValue(typeof(TDbContext), out bool shouldRunMigrations);
 22
 623        if (!shouldRunMigrations)
 024            return;
 25
 626        var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
 627        await dbContext.Database.MigrateAsync(cancellationToken);
 628    }
 29}