< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Data.Configuration.DesignTimeDbContextFactory
Assembly: ArturRios.Heimdall.Data
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Infrastructure/ArturRios.Heimdall.Data/Configuration/DesignTimeDbContextFactory.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 36
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage
0%
Covered methods: 0
Fully covered methods: 0
Total methods: 1
Method coverage: 0%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateDbContext(...)0%620%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Infrastructure/ArturRios.Heimdall.Data/Configuration/DesignTimeDbContextFactory.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.EntityFrameworkCore.Design;
 3using Microsoft.Extensions.Logging.Abstractions;
 4
 5namespace ArturRios.Heimdall.Data.Configuration;
 6
 7/// <summary>
 8///     Builds an <see cref="AppDbContext" /> for the EF Core command-line tools, which have no
 9///     access to the application's dependency-injection container. The connection string comes from
 10///     <c>HEIMDALL_DATA_CONNECTIONSTRING</c>; <c>scripts/migrations.py</c> loads it from the
 11///     selected environment file before invoking <c>dotnet ef</c>. Diagnostics are disabled — design
 12///     time never needs them, and the tools may well be pointed at production.
 13/// </summary>
 14public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
 15{
 16    private const string ConnectionStringVariable = "HEIMDALL_DATA_CONNECTIONSTRING";
 17
 18    public AppDbContext CreateDbContext(string[] args)
 19    {
 020        var connectionString = Environment.GetEnvironmentVariable(ConnectionStringVariable);
 21
 022        if (string.IsNullOrWhiteSpace(connectionString))
 23        {
 024            throw new InvalidOperationException(
 025                $"Environment variable '{ConnectionStringVariable}' is unset. Run scripts/migrations.py, " +
 026                "which loads it from the environment file you select, or set it manually before " +
 027                "invoking dotnet ef.");
 28        }
 29
 030        var options = new DbContextOptionsBuilder<AppDbContext>()
 031            .UseNpgsql(connectionString)
 032            .Options;
 33
 034        return new AppDbContext(options, NullLoggerFactory.Instance, DbContextDiagnosticsOptions.Disabled);
 35    }
 36}