Files
Teamup/src/Modules/TeamUp.Modules.Governance/Persistence/GovernanceDbContextFactory.cs
T

22 lines
802 B
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace TeamUp.Modules.Governance.Persistence;
/// <summary>Design-time factory so `dotnet ef` can build the internal context without a host.</summary>
internal sealed class GovernanceDbContextFactory : IDesignTimeDbContextFactory<GovernanceDbContext>
{
public GovernanceDbContext CreateDbContext(string[] args)
{
var connectionString =
Environment.GetEnvironmentVariable("ConnectionStrings__Postgres")
?? "Host=localhost;Port=5432;Database=teamup;Username=teamup;Password=teamup";
var options = new DbContextOptionsBuilder<GovernanceDbContext>()
.UseNpgsql(connectionString)
.Options;
return new GovernanceDbContext(options);
}
}