< Summary

Information
Class: Elsa.Persistence.EFCore.DbSchemaAwareMigrationAssembly
Assembly: Elsa.Persistence.EFCore.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/DbSchemaAwareMigrationAssembly.cs
Line coverage
80%
Covered lines: 8
Uncovered lines: 2
Coverable lines: 10
Total lines: 40
Line coverage: 80%
Branch coverage
50%
Covered branches: 3
Total branches: 6
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%
CreateMigration(...)50%7675%

File(s)

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

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Reflection;
 3using Microsoft.EntityFrameworkCore;
 4using Microsoft.EntityFrameworkCore.Diagnostics;
 5using Microsoft.EntityFrameworkCore.Infrastructure;
 6using Microsoft.EntityFrameworkCore.Migrations;
 7using Microsoft.EntityFrameworkCore.Migrations.Internal;
 8
 9namespace Elsa.Persistence.EFCore;
 10
 11/// <summary>
 12/// Class That enable Schema change for Migration
 13/// </summary>
 14[SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Required to customize migration assembl
 15public class DbSchemaAwareMigrationAssembly(
 16    ICurrentDbContext currentContext,
 17    IDbContextOptions options,
 18    IMigrationsIdGenerator idGenerator,
 19    IDiagnosticsLogger<DbLoggerCategory.Migrations> logger)
 620    : MigrationsAssembly(currentContext, options, idGenerator, logger)
 21{
 622    private readonly DbContext _context = currentContext.Context;
 23
 24    public override Migration CreateMigration(TypeInfo migrationClass, string activeProvider)
 25    {
 4426        if (activeProvider == null)
 027            throw new ArgumentNullException(nameof(activeProvider));
 28
 4429        var hasCtorWithSchema = migrationClass.GetConstructor([typeof(IElsaDbContextSchema)]) != null;
 30
 4431        if (hasCtorWithSchema && _context is IElsaDbContextSchema schema)
 32        {
 4433            var instance = (Migration)Activator.CreateInstance(migrationClass.AsType(), schema)!;
 4434            instance.ActiveProvider = activeProvider;
 4435            return instance;
 36        }
 37
 038        return base.CreateMigration(migrationClass, activeProvider);
 39    }
 40}